Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose build, how to tag image

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.

like image 891
Tuomas Toivonen Avatar asked Jun 06 '18 15:06

Tuomas Toivonen


People also ask

How do I tag a docker image in a building?

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 .

How do I tag a docker compose file?

Add docker-compose tag <service> <tag> and allow to push a specific tag by using push command #7669.

How do I tag a docker image and push?

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.

Which command is used to build and tag the docker image?

With Dockerfile written, you can build the image using the following command: $ docker build .


1 Answers

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
like image 148
sp0gg Avatar answered Oct 30 '22 19:10

sp0gg