I have the following docker-compose
file
version: '3'
services:
node1:
build: node1
container_name: node1
node2:
build: node2
container_name: node2
Here is the Dockerfile of node1
FROM ubuntu
RUN apt-get update && apt-get install -y iputils-ping
COPY true.sh /var/
CMD ["/var/true.sh"]
node2 Dockerfile extends node1 as follows
FROM node1
RUN apt-get update && apt-get install -y iputils-ping
COPY true.sh /var/
CMD ["/var/true.sh"]
Now when I build images with docker-compose up -d --build
, having initially empty local image repository, I get the following error
ERROR: Service 'node2' failed to build: pull access denied for node1, repository does not exist or may require 'docker login'
How could I define the tag, when using compose to build the images? For now, following images are built
REPOSITORY TAG IMAGE ID CREATED SIZE
docker_node1 latest 52dd5a083162 7 minutes ago 123MB
ubuntu latest 113a43faa138 19 hours ago 81.2MB
I know I could build the images with vanilla docker, but I like the idea of having all the necessary configuration for a newcomer to bootstrap a fresh environment with a single commands, and let the same command to restart changed containers as changes are made to their builds.
When we use the Docker build command to build an image from a Dockerfile, we use the -t option to give a name and tag to the image. For example, let's check out the Dockerfile and the command below. $ docker build -t myubuntuimage:version1 .
Add docker-compose tag <service> <tag> and allow to push a specific tag by using push command #7669.
Step 1: The first step is to give a tag to your docker image which is a reference to your docker image ID which conveys the information regarding the image version. If you login to your docker hub account and search for a standard image of MySQL, HTTP, etc there you notice these tags.
With Dockerfile written, you can build the image using the following command: $ docker build .
Adding the image
directive when a build
directive exists in a service will name and tag the built image:
version: '3'
services:
node1:
build: node1
container_name: node1
image: node1:latest
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