Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Update a Running Docker Container

Pull the newest image and recreate the container, with plain Docker or with Docker Compose.

VPS and Cloud Servers2 min read4 steps1 screenshot

Why update containers

A container never updates by itself. New images bring security fixes, bug fixes and new features, so you should update them regularly.

An existing container is built from a fixed image. To use a new image you must create a new container from it. Your data survives if it is stored in a volume or bind mount.

The workflow to update a Docker container

Basic workflow

  1. Download the latest image from the registry.
  2. Stop the running container.
  3. Remove the old container.
  4. Start a new container from the updated image with the same settings.

Update with Docker

Step 1: Pull the latest image

docker pull image_name:latest

Step 2: Stop the container

docker stop container_name

Step 3: Remove the old container

docker rm container_name

Step 4: Start a new one from the updated image

docker run -d --name container_name image_name:latest
Warning: Use the same options as before (ports, volumes, environment variables, restart policy), or the new container will behave differently. Check the old settings with docker inspect container_name. Data inside the container that is not in a volume is lost when you remove it.

Remove the old, unused images afterwards:

docker image prune

Update with Docker Compose

Compose keeps all the settings in docker-compose.yml, so updates are simple.

Go to the folder of the project and run:

docker compose pull
docker compose up -d

docker compose pull downloads the new images. docker compose up -d recreates only the containers whose image changed.

To update one service:

docker compose pull web
docker compose up -d web

Update automatically (optional)

Tools such as Watchtower check for new images and update containers for you. Use them with care on production servers, because an unplanned update can break an app. Pin version tags (for example nginx:1.27) when you need predictable changes.

Tips

  • Back up volumes before major updates.
  • Read the release notes of the image.
  • Test the new version on a staging container first.
  • Check the logs after the update: docker logs container_name.

Quick recap

  • docker pull, stop, rm, run for a single container.
  • docker compose pull && docker compose up -d for Compose.