How Updating a Container Works
A container is created from an image, and the image never changes underneath it. To run a newer version you replace the container:
- Pull the new image.
- Stop and remove the old container.
- Start a new container from the new image with the same options and the same volumes.
Anything written inside the container itself, outside a volume or bind mount, is lost in step 2. Check where the data lives before you start.
Before You Start: Data and a Backup
docker inspect -f '{{json .Mounts}}' webThis lists the volumes and bind mounts of the container named web. If it prints an empty list, the container keeps its data inside itself; copy it out with docker cp before you go on.
Back up the volume. Stop the container so the files do not change during the copy:
docker stop web
docker run --rm -v web_data:/data:ro -v "$PWD":/backup alpine tar czf /backup/web_data.tar.gz -C /data .
docker start webFor a database, a dump made with the database's own tool is the better backup. A server snapshot in your provider's control panel adds a second safety net; see snapshot vs backup.
Step 1: Write Down the Options
The new container needs the same ports, volumes, environment variables, network, and restart policy. Read them from the old one:
docker inspect web
docker port webThe output includes the environment variables, passwords among them, so do not paste it anywhere public. Keeping the full docker run command in a script avoids this step next time; see how to write a bash script.
Step 2: Pull the New Image
docker pull nginx:1.30.8Pulling first keeps the downtime short: the old container keeps serving while the download runs.
Step 3: Replace the Container
docker stop web
docker rename web web-old
docker run -d --name web \
-p 8080:80 \
-v web_data:/usr/share/nginx/html \
--restart unless-stopped \
nginx:1.30.8Renaming instead of removing keeps a way back. Check the new container:
docker ps
docker logs --tail 50 webStep 4: Remove the Old One or Roll Back
When the new version works, remove the old container and then its image, named by the tag it had before:
docker rm web-old
docker image rm nginx:OLD_TAGIf it does not work, go back:
docker rm -f web
docker rename web-old web
docker start webSome applications change their data format during an upgrade, and the old version may not read it any more. That is the case the backup is for.
With Docker Compose
Compose keeps the options in the file, so the update is two commands in the project folder:
docker compose pull
docker compose up -dCompose replaces only the containers whose image changed and keeps the named volumes. To change the version, edit the tag in compose.yaml first. More options are in docker compose up -d.
Pin Tags in Production
- Avoid latest:
latestis whatever was pushed last. A restart months later can bring a new major version you did not plan for. - Use a version tag:
nginx:1.30follows the patch releases of one line;nginx:1.30.8stays on one exact version. - Read the release notes: before a jump between major versions, especially for databases.
What docker update Does
The command named docker update does not update the image. It changes the resource limits (CPU, memory, process count) and the restart policy of an existing container, without restarting it:
docker update --cpus 2 --memory 2g --memory-swap 2g web
docker update --restart unless-stopped webPorts, volumes, and environment variables cannot be changed this way; for those you replace the container as shown above.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations