I have a few docker containers that I try to sync with docker-compose
(currently are being run by bash scripts). I'm looking for a way to tag and push them to our ec2 based dockerhub (private server).
Using simply docker
we did something like this (for each container):
$ docker build -f someDockerfile -t some
$ docker tag some <docker_hub_server>/some
$ docker push <docker_hub_server>/some
I'm trying to replicate this in docker-compose
. I tried a few things but this one seems close to working (but didn't work of course):
docker-compose.yml:
version: '3'
services:
some:
container_name:some
image: some:<docker_hub_server>/some
But when i run:
$ docker-compose push
I get:
Pushing some (base:<docker_hub_server>/base:latest)...
ERROR: invalid reference format
Any ideas on how I can tag and push my containers?
p.s.: I know that this is not the way docker-compose
is meant to be used, but I also know it's possible and it fits my needs.
Functions of Docker Push As we know, we can share images to the public registry or private registry. When we push any image, Docker daemon first checks its tag, how the image is tagged to determine where to push the image.
Creates containers for a service. Receive real time events from containers. Execute a command in a running container. Force stop service containers.
To push an image to Docker Hub, you must first name your local image using your Docker Hub username and the repository name that you created through Docker Hub on the web. You can add multiple images to a repository by adding a specific :<tag> to them (for example docs/base:testing ).
You can still find Docker Compose V1 in the `master` branch. Compose V1 is marked as deprecated, and we'll begin patching only high-severity vulnerabilities or fixing critical bugs until the next milestone. Developers can continue to alias docker-compose to use docker compose.
I have tested this approach with Docker Hub, so you should be able to achieve what you want with the following configuration and shell session:
docker-compose.yml
version: '3'
services:
build-1:
build:
context: ./build-1
image: user/project-1
build-2:
build:
context: ./build-2
image: user/project-2
(Here, you should replace user/project-1
with registry.name/user/project-1
if you are not using Docker Hub but another Docker registry, e.g., quay.io/user/project-1
.)
The various fields involved here (build:
, context:
, etc.) are described in this page of the docker-compose documentation.
The docker-compose.yml
file above assume you have the following tree (including a .gitignore and some .dockerignore files, to comply with best practices):
.
├── build-1
│ ├── Dockerfile
│ └── .dockerignore
├── build-2
│ ├── Dockerfile
│ └── .dockerignore
├── docker-compose.yml
└── .gitignore
Then do in a terminal:
$ docker login
# → append the domain name of your Docker registry
# if you are not using Docker Hub; for example:
# docker login quay.io
$ docker-compose build --pull
$ docker-compose push
# and optionally:
$ docker logout
Finally, below are some remarks to clarify a few details related to your question:
In your example session
$ docker build -f someDockerfile -t some . # with "." as context build path
$ docker tag some …/some
$ docker push …/some
some
is a temporary image name (not a container) so it seems unnecessary: you could just as well have run the following, with the same outcome.
$ docker build -f someDockerfile -t …/some .
$ docker push …/some
Your docker-compose.yml
example contained the line:
image: some:<docker_hub_server>/some
Actually, the image tags can contain :
to specify a version, but not in this way (it should be a suffix). For example, you could tag an image user/some:1.0
or user/some:latest
, and by convention this latter example user/some:latest
admits user/some
as a shorter, equivalent name.
Note that the full syntax for image tags is
registry.name:port/user/project:version
where registry.name
should be the domain name or hostname of the desired Docker registry (if omitted, it will default to Docker Hub).
This is mentioned in that page of the official documentation.
So for example, if you use the Quay Docker registry, the image tag could be quay.io/user/some:latest
or more succinctly quay.io/user/some
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With