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
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
.