← Blog

DIND - docker push catch

Introduction

In this blogpost, I wrote about how we can volume map the Docker socket file and run docker commands with the docker daemon in the host system from inside a docker container.

Problem

Extending on that idea, at work, I had to push docker images to the local docker registry. But I couldn’t, I got a Push access denied error.

  • It definitely wasn’t an access issue with the registry, because I could push the same image from the host system.
  • The only other issue would have been with the DIND setup.

Debugging and workaround

So there could have been one of the two issues here,

  1. Either that DIND setup doesn’t allow pushing images to registry, which wasn’t true from a quick internet search.
  2. There could be permission issues from the docker container, to push images.

Diving deeper into 2, I execed into the container and tried pushing the image, only to get the same error.

So I did docker login inside the container, and then pushed, which worked!

Now, the solution was to persist the docker login activity from the start as a volume mount.

As described here, docker login persists access tokens at ~/user/.docker/config.

I execed into the container again, found that it’s stored at /root/.docker/config. Added the following to my docker-compose file, and docker push worked from within the container. 🎉

~/.docker/config.json:/root/.docker/config.json