Using 'docker login' with 'setup_remote_docker' to push to a private repository?

I am attempting to have CircleCI automatically build and push a docker container to a private repository using these steps:

setup_remote_docker
docker login “<Private Registry>” -u “<Username>” -p “<Password>”
docker build --tag <Private Registry>/<Container Name>:<Container Version> .
docker push <Private Registry>/<Container Name>:<Container Version>

Login reports success, as does build, however push fails with an ‘unauthorized: authentication required’ error. I can also see that ‘~/.docker/config.json’ is correct.

I’m assuming this is because build and push are run in the context of the remote docker environment while login is only run in the context of my primary container.

Is there a way to get authentication working in the remote docker environment?

I had a look at the ‘Using Private Images’ help document but that only covers pulling from a private repository not pushing. I did attempt to put in authentication details that way but doing so prevented me from being able to pull ‘Docker’ as my primary container.

This works for me on CodeFresh, as I show here. I wonder if you are using your registry password however, when for the -p flag you might need to use a token instead.

I don’t know if this varies from registry to registry. Are you using a hosted registry like Docker Hub?

Thanks for the reply.

I am using Azure ACR as my private repository, outside of CircleCI the docker login command works fine with the same values for -u and -p do I don’t believe it is that.

Hmm, that is odd. I am not sure what to suggest. I think if I were investigating this, I would run the failing job with SSH, and then play around in the build container itself to see if I can get docker login to work. Just be aware this is a good way to eat your build minutes, so remember to exit SSH and then cancel the job afterwards in the Circle UI.