Updating docker image with new code
You could try docker-compose up --force-recreate
; or if you make changes to the Dockerfile you may have to rebuild it. You can do so by using docker-compose build
(you could append --no-cache
at the end to force-download the dependencies etc.).
Note that, in some cases you may have to delete created images/builds/containers using docker system prune
(you could append -a at the end of it to also remove any stopped containers and all unused images -- not just dangling images). Then do a build using docker-compose build
.
You could also use docker stop $(docker ps -a -q)
followed by docker rm $(docker ps -a -q)
to stop and remove all docker containers.
Hopefully this would point you in the right direction, good luck!
There are two options.
- If you use docker-compose commands,
1.1. first, remove the previous image by running,
docker rmi 'image_id' or docker rmi -f 'image_id'
1.2. Then recreate the image by running,
docker-compose up
If you are using docker commands run,
docker build
Dockerfile
takes care of creating a docker image that can be used to run containers. If you would like to update the image configuration or the code base of your application which inside the image you need to rebuild the image.
For instance you might have a Dockerfile that pulls the codebase during the build process in this case you need to rebuild the image whenever there is a new code that needs to be included. or lets say you need to update the production version of your application then you need to rebuild the image which contains a new version of the stable branch of your application.
Also if you are using it for development then you might need to mount the application directory as a volume which makes you able to see the changes immediately without the need to rebuild your docker image unless there is a need to do it.
For docker-compose
you can consider it similar to docker run
command which provides an easier way to run a container from a specific image including exposing ports or mounting volumes or linking multiple container together, etc..
References:
- Use volumes | Docker Documentation
- Overview of Docker Compose | Docker Documentation