Recreate a container upgrading image

Hello there, I’ve been using Docker for a while but I’m new to this forum. I use Docker to deploy services developed by my company, and we constantly need to update the service by recreating the container with the newest image.

As I have many clients and deploy the container on each client server, recreating all containers is challenging and takes hours.

I’ve tried developing a bash script to inspect, copy information, and deploy a new container with the new image. Sometimes it works, sometimes it doesn’t.

Does anyone know a different way to do this? I was hoping Docker had a command to upgrade images.

Thanks.

Do you use Docker Compose? If so

docker compose pull <service>
docker compose up -d <service>

This would update the image and recreate the container with it

1 Like

I am not using Docker Compose… maybe a should, but is there any solution to upgrade image version using Docker CLI… or perhaps is there an open source project that does it?

A. If you’re currently using just the Docker CLI, yes, Docker Compose would help you and simplify your container management

B. You cannot update an existing container. You can remove it, pull the latest version of the image, and then recreate it with the same preferences (That’s why Docker Compose comes in handy, specifying all those preferences in the YAML file instead of the docker run command)

1 Like

Make sure to use Docker volumes or bind mounts for data that needs to be persisted across the container re-creation process.