Tuomas Toivonen
Tuomas Toivonen

Reputation: 23492

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.

Upvotes: 11

Views: 18043

Answers (1)

sp0gg
sp0gg

Reputation: 4122

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

Upvotes: 15

Related Questions