Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile and docker-compose not updating with new instructions

When I try to build a container using docker-compose like so

nginx:   build: ./nginx   ports:     - "5000:80" 

the COPY instructions isnt working when my Dockerfile simply looks like this

FROM nginx  #Expose port 80 EXPOSE 80  COPY html /usr/share/nginx/test  #Start nginx server RUN service nginx restart 

What could be the problem?

like image 269
Leon Avatar asked Feb 05 '16 18:02

Leon


People also ask

Can Dockerfile work with docker compose?

Docker Compose (herein referred to as compose) will use the Dockerfile if you add the build command to your project's docker-compose. yml . Your Docker workflow should be to build a suitable Dockerfile for each image you wish to create, then use compose to assemble the images using the build command.

Does docker compose auto update?

In this tutorial, you will use Watchtower with both Docker's run command and Docker Compose to automatically update a Docker image. Both methods are functionally the same in creating a container running Watchtower, then pointing it towards a container you wish to keep automatically updated.


2 Answers

It seems that when using the docker-compose command it saves an intermediate container that it doesnt show you and constantly reruns that never updating it correctly. Sadly the documentation regarding something like this is poor. The way to fix this is to build it first with no cache and then up it like so

docker-compose build --no-cache docker-compose up -d 
like image 86
Leon Avatar answered Sep 29 '22 15:09

Leon


I had the same issue and a one liner that does it for me is :

docker-compose up --build --remove-orphans --force-recreate

  • --build does the biggest part of the job and triggers the build.
  • --remove-orphans is useful if you have changed the name of one of your services. Otherwise, you might have a warning leftover telling you about the old, now wrongly named service dangling around.
  • --force-recreate is a little drastic but will force the recreation of the containers.

Reference: https://docs.docker.com/compose/reference/up/

Warning I could do this on my project because I was toying around with really small container images. Recreating everything, everytime, could take significant time depending on your situation.

like image 42
Philippe Boulanger Avatar answered Sep 29 '22 16:09

Philippe Boulanger