Compose: docker-compose up assumes --no-build

Created on 10 Jul 2015  Â·  12Comments  Â·  Source: docker/compose

It seems if I try to run docker-compose up with a yml that uses build: . and the image does not already exist, it acts like --no-build is passed.

This is on version 1.3.1

areup kinbug

Most helpful comment

@dnephin I re-read your comment above:

up should build if the image doesn't already exist (but not if it exists)

So if my image exists (because I ran docker-compose build before), but the referred Dockefile changes, up won't trigger an automatic rebuild? It may be a misunderstanding, but I thought that up always rebuilds the image if the Dockerfile is out of sync with the image, unless --no-build is passed.

All 12 comments

up should build if the image doesn't already exist (but not if it exists). Could you provide a log sample of the output and error you're seeing?

I can't seem to replicate it now which is odd. Will update if it repeats.

I had the same problem with

django:
build: .

changing it to

web:
build: .

makes it work

Don't see what would be wrong with the 1st one.

I also had the error if I manually delete a container which is part of the docker-compose set with the docker command.

This is how I am able to reproduce it every time. docker-compose up does not rebuild a container, if the _Dockerfile_ has changed:

$ mkdir mycont
$ echo "FROM busybox" > mycont/Dockerfile
$ echo -e "mycont:\n  build: mycont/" > docker-compose.yml
Building mycont...
# output, press ctrl + c to stop container
$ echo "ENV foo bar" >> mycont/Dockerfile
$ docker-compose up
Recreating test_mycont_1...  

the container _mycont_ is not rebuild, even though the Dockerfile has changed.

I've installed docker-compose using pip. Version information:

$ docker-compose -v                                                                                │ 38 RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
docker-compose version: 1.3.3                                                                                          │ 39
CPython version: 2.7.6                                                                                                 │ 40 # Create user
OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014

@dnephin I re-read your comment above:

up should build if the image doesn't already exist (but not if it exists)

So if my image exists (because I ran docker-compose build before), but the referred Dockefile changes, up won't trigger an automatic rebuild? It may be a misunderstanding, but I thought that up always rebuilds the image if the Dockerfile is out of sync with the image, unless --no-build is passed.

@thewilli up only checks that the image exists, not that it's up-to-date. There's actually no way to check that.

We've discussed alternative approaches, including always building and never building.

I'm seeing the same behavior as reported by the OP.

$ docker-compose version
docker-compose version: 1.4.2
docker-py version: 1.3.1
CPython version: 2.7.9
OpenSSL versionL OpenSSL 1.0.1e 11 Feb 2013

I just added a new service to a docker-compose.yml file, which has build: path/. When I run docker-compose up, I get the following message:

Service 'web' needs to be built, but --no-build was passed.

I didn't pass --no-build.

This behavior is unexpected, as docker-compose up --help says:

Builds, (re)creates, starts, and attaches to containers for a service.

I just hit this myself as well when I went and changed a service from image to build. The workaround for now is to docker rm <container name> where the container name is the compose form of <projectname>_<servicename>_1

@dnephin Actually, I was mistaken. I did the same thing as you - I changed an existing service from image to build. Thanks for the workaround.

Thanks very much for the fix!

But is there a workaround for this? I'd upgrade compose, but I'm currently stuck using an older version due to #17804

Was this page helpful?
0 / 5 - 0 ratings

Related issues

29e7e280-0d1c-4bba-98fe-f7cd3ca7500a picture 29e7e280-0d1c-4bba-98fe-f7cd3ca7500a  Â·  3Comments

maltefiala picture maltefiala  Â·  3Comments

bergtwvd picture bergtwvd  Â·  3Comments

dimsav picture dimsav  Â·  3Comments

davidbarratt picture davidbarratt  Â·  3Comments