Naftuli Kay
Naftuli Kay

Reputation: 91630

Build multiple images with Docker Compose?

I have a repository which builds three different images:

  1. powerpy-base
  2. powerpy-web
  3. powerpy-worker

Both powerpy-web and powerpy-worker inherit from powerpy-base using the FROM keyword in their Dockerfile.

I'm using Docker Compose in the project to run a Redis and RabbitMQ container. Is there a way for me to tell Docker Compose that I'd like to build the base image first and then the web and worker images?

Upvotes: 3

Views: 3972

Answers (2)

dnephin
dnephin

Reputation: 28060

You can use depends_on to enforce an order, however that order will also be applied during "runtime" (docker-compose up), which may not be correct.

If you're only using compose to build images it should be fine.

You could also split it into two compose files. a docker-compose.build.yml which has depends_on for build, and a separate one for running the images as services.

These is a related issue: https://github.com/docker/compose/issues/295

Upvotes: 4

ashatrov
ashatrov

Reputation: 1112

About run containers:

It was bug before, but they fixed it since docker-compose v1.10. https://blog.docker.com/2016/02/docker-1-10/

Start linked containers in correct order when restarting daemon: This is a little thing, but if you’ve run into it you’ll know what a headache it is. If you restarted a daemon with linked containers, they sometimes failed to start up if the linked containers weren’t running yet. Engine will now attempt to start up containers in the correct order.

About build: You need to build base image first.

Upvotes: 1

Related Questions