Problem I am facing:
- I have a docker-compose setup on my server
- I want to build docker images for my projects (I use drone.io) and store them on said server
- I want to create containers using my private images in my compose setup
What I did:
I did not want to push my private docker image to DockerHub so I decided to create a registry container in my docker-compose setup (CI pushes docker images there automatically). Now, I would like to use that image in the very same docker-compose file as I expected it would be pulled from registry easily.
Relevant part of my docker-compose.yml file for better visualisation:
version: "3.7"
services:
myimage:
image: registry.example.com:5000/username/myimage
depends_on:
- registry
networks:
- traefik_public
labels:
// traefik labels
registry:
image: registry:2
networks:
- traefik_public
ports:
- '5000:5000'
labels:
// traefik labels giving this container 'registry.example.com' domain
Instead, I immediately realized I broke my setup as calling:
docker-compose up -d
produced the following output:
Network traefik_public is external, skipping
Pulling myimage (registry.example.com:5000/username/myimage:)...
ERROR: Get https://registry.example.com:5000/v2/: dial tcp MY-IP:5000: connect: connection refused
That is understandable, registry container is not running and therefore could not provide required image to create & run 'myimage'.
Putting 'depends_on' to the 'myimage' definition does not help either, as I suppose it is a "runtime" delay mechanism and does not affect the pulling of image.
Workaround:
- port-forwarded MY-IP:5000 to machine_running_docker:5000
- comment out 'myimage'
- docker-compose up <- gets registry up and running
- remove comments around 'myimage'
- docker-compose up -d myimage
- profit
The above steps work, but unfortunately are unacceptable for me as they completely mitigate any value of having all the containers in a single file and make starting/stopping of containers really inconvenient.
How to tackle this? How and where should I store my docker images so that I am able to use them in my compose setup? Is it doable using private registry somehow or not?