Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update existing images with docker-compose?

People also ask

Does Docker compose update images?

Docker Compose has a built-in pull command that will pull updated versions of all the images in your stack.

Can we make changes to existing docker image and create a new image out of it?

Create a Docker image from an existing container: In this case, you start with an existing image, customize it with the changes you want, then build a new image from it. Use a Dockerfile: In this case, you use a file of instructions -- the Dockerfile -- to specify the base image and the changes you want to make to it.


Docker containers are designed to be ephemeral. To update an existing container, you remove the old one and start a new one. Thus the process that you are following is the correct one.

You can simplify the commands to the following ones:

docker-compose up --force-recreate --build -d
docker image prune -f

You can update it using:

docker-compose pull

Now your image is updated. If you have the previous version of container running you should restart it to use the updated image:

docker-compose up --detach

up command automatically recreates container on image or configuration change.


I prefer to ensure all the images are downloaded before updating the containers with the new images to minimize the time in an intermediate state or worse being in the middle in case the download of an image fails.

1) I pull latest images:

docker-compose pull

2) Then I restart containers:

docker-compose up -d --remove-orphans

3) Optionally, I remove obsolete images:

docker image prune

docker-compose pull

then

docker-compose up -d

you don't need "down" "docker-compose up -d" command will only recreate changed one