4

I am building a lamp with docker-compose.

In my docker-compose.yml i have the following:

ubuntu-base:
    build: ./ubuntu-base

webserver-base:
    build: ./webserver-base

webserver-base is derived from the ubuntu-base image. In webserver-base Dockerfile:

FROM docker_ubuntu-base

ubuntu-base is built

FROM ubuntu:14.04

Now, if i execute the docker-compose.yml, it does not build the ubuntu-base image, but its trying to build the webserver-base image and fails, because it does not find the ubuntu-base image.

Output:

$ docker-compose up -d
Building webserver-base
Step 1 : FROM docker_ubuntu-base
Pulling repository docker.io/library/docker_ubuntu-base
ERROR: Service 'webserver-base' failed to build: Error: image library/docker_ubuntu-base:latest not found

It all works if i build the ubuntu-base image manually first.

why does it not build the ubuntu-base image?

2 Answers 2

6

Sadly, build ordering is a missing feature in docker-compose, that is requested for many month now.

As workaround you can link the containers like this:

ubuntu-base:
    build: ./ubuntu-base

webserver-base:
    build: ./webserver-base
    links:
      - ubuntu-base

this way ubuntu-base gets built before webserver-base.

3
  • Hi, thanks for tip. Today is 2016, did you found any better way?
    – woto
    Nov 17, 2016 at 17:28
  • hmm, may by i'm misunderstood, but depends_on does not affect on build order. I'll try it later, still interesting in this feature.
    – woto
    Nov 21, 2016 at 14:53
  • ok, please share your results. since i did not test this myself, but only read about it in github.com/docker/compose/issues/295, i will change my answer according to your feedback. Or write an answer yourself, i will vote it up
    – cari
    Nov 21, 2016 at 15:05
3

First do a

docker-compose build ubuntu-base

But this will not create the image docker_ubuntu-base locally because you do not have any build steps. Only docker.io/ubuntu:14.04 will be downloaded.

If you add a build step like:

FROM ubuntu:14.04
RUN date

A docker_ubuntu-base image will be created.

So first do a:

docker-compose build ubuntu-base

This will create the image docker_ubuntu-base. Then you can do a docker-compose build.

But I would advise against this nested-docker image construction. This is cumbersome because as @kev indicated you have no control over the order of the builds. Why don't you create two independent docker files? Let docker derive webserver-base from ubuntu-base by keeping the Dockerfile instructions as identical as possible and reusing the layers.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.