Updating Containers
This guide explains how to check if Docker containers are outdated and update them safely.
How Updates Work
Section titled “How Updates Work”- Pull latest image - Downloads new image layers from Docker Hub
- Recreate container -
docker compose up -ddetects new image and recreates - Verify - Compare running container image ID with local image ID
Important:
- Containers don’t auto-update when images change
- Old images remain until removed (
docker image prune) - Data in volumes is preserved during update
Check if Update Needed
Section titled “Check if Update Needed”Step 1: Get running container image ID
Section titled “Step 1: Get running container image ID”docker inspect <container_name> --format '{{.Image}}'Step 2: Pull latest image
Section titled “Step 2: Pull latest image”docker pull <image>:latestStep 3: Compare with local image
Section titled “Step 3: Compare with local image”docker images --format "{{.ID}}" <image>:latestIf the IDs differ, an update is needed.
Update the Container
Section titled “Update the Container”cd /opt/docker/<service>docker compose up -dThis recreates the container with the new image while preserving volumes.
Verify Update
Section titled “Verify Update”docker inspect <container_name> --format '{{.Image}}'Should now match the local image ID.
Real Example: n8n Update
Section titled “Real Example: n8n Update”Before Update
Section titled “Before Update”$ docker inspect n8n --format '{{.Image}}'sha256:c52e366997414009f8a8cdb6b6e87f7d198c93ba7ce341626cd1510f771b8902Pull Latest Image
Section titled “Pull Latest Image”$ docker pull n8nio/n8n:latestDigest: sha256:94f108ec1ed2ee17198fff2432d580b184b54c609bc23e27889f5ed6b98a4789Status: Image is up to date for n8nio/n8n:latestCompare
Section titled “Compare”$ docker images --format "{{.ID}}" n8nio/n8n:latest05ec79d62bc4Running ID (c52e36699741) ≠ Latest ID (05ec79d62bc4) → Update needed
Update Container
Section titled “Update Container”$ cd /opt/docker/n8n$ docker compose up -d Container n8n Recreate Container n8n Recreated Container n8n Starting Container n8n StartedAfter Update
Section titled “After Update”$ docker inspect n8n --format '{{.Image}}'sha256:05ec79d62bc4c2ee6b7b53449e8e90944439f7a6967d77e78fcc9d1c409d5e07
$ docker images --format "{{.ID}}" n8nio/n8n:latest05ec79d62bc4IDs match - update successful.
Quick Status Check Script
Section titled “Quick Status Check Script”Check all containers at once:
echo "Container Status Check"echo "======================"
for container in traefik n8n postgres-main adminer promtail; do image=$(docker inspect $container --format '{{.Config.Image}}' 2>/dev/null) running=$(docker inspect $container --format '{{.Image}}' 2>/dev/null | cut -c8-19) latest=$(docker images --format "{{.ID}}" $image 2>/dev/null)
if [ "$running" = "$latest" ]; then status="OK" else status="OUTDATED" fi
printf "%-15s %s\n" "$container:" "$status"doneCleanup Old Images
Section titled “Cleanup Old Images”After updating, remove unused images:
docker image prune -fThis removes dangling images (untagged layers from old versions).
Related Guides
Section titled “Related Guides”- Server Context - Container inventory and update commands