Dockerfile and docker-compose not updating with new instructions
Solution 1
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
Solution 2
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.
Leon
Updated on January 21, 2022Comments
-
Leon over 2 years
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?