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?
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With