Docker Login with --password-stdin (2.0)

Hi all,

I’m new to CircleCI and am wondering if anyone has found an elegant solution to this problem:

I’m building a docker image and pushing to a private repo on docker hub, which means I need to log in to docker.

I’ve tried the docker login syntax with -u and -p (ie docker login -u username -p password) and docker rejects my login. https://docs.docker.com/engine/reference/commandline/login/#extended-description describes why this is the case and provides an example of standard in usage with:

cat ~/my_password.txt | docker login --username foo --password-stdin

In CircleCI context, this to me means that I need to save my docker password to a file, in my repo. Which I really don’t want to do.

My question then is how have people worked around this, has anyone seen a nice solution?
I’ve had a think about using circle contexts aka environment variables, but this would still not be piping in from std in so am a bit confused as to the best way of doing this.

I’d love any advice you more experience circleci people have :slight_smile:

I’m using Node 7.10.0 to package an Ionic Web App, and Java 8 for a spring boot API
Docker on circle is giving me a message that my password is invalid (it’s not) because it wants the input via std in as per docs linked above
The specific step is

  - run:
      name: Docker Login
      command: 'docker login -u MYUSERNAME -p MYPASSWORD'

Thanks all :slight_smile:

  1. Add your docker credentials to the project environment variables. (Build settings -> environment variables). Use DOCKER_USER and DOCKER_PASS as name for the variables
  2. Alter your command to: docker login -u $DOCKER_USER -p $DOCKER_PASS

See:https://circleci.com/docs/2.0/building-docker-images/