This Bash script is a comprehensive tool for managing and safely updating Docker containers and services. It supports Docker Swarm, Dockerfile-built containers, interactive updates, and network inspection, with built-in logging, rollback support, and Compose detection.
The script provides a user-friendly terminal menu and ensures all updates are performed using the safest and most Docker-compliant methods.
- Docker: Must be installed and running.
- jq: JSON parser used for inspecting container configurations.
Install jq (if missing):
sudo apt install jq- Safe Swarm updates using
docker service update --image - Rollback support by saving
docker inspectJSON before changes - Compose awareness: detects and labels Docker Compose containers
- Dockerfile container updates via rebuilds
- Interactive configuration inspection
- Network mapping and visualization
- Security scan (exposed ports summary)
- Full update summary logging
- Export of container configurations
Make the script executable:
chmod +x update_docker_container.shRun it:
./update_docker_container.sh- Pulls the latest image for each Swarm service.
- Updates each service with
docker service update --image. - Logs summary to
summary.log.
- Detects locally built images (
<none>or no repository prefix). - Asks for Dockerfile path and rebuilds image.
- Restarts container with same name.
- Logs changes to
dockerupdatelog.txt.
- Shows container configuration: image, ports, env, mounts.
- Allows user to inspect or modify before manual update.
- Lists all Docker networks.
- Shows connected containers and their IPs.
- Outputs to
network_map.txt.
- Lists saved container configurations.
- Allows manual restore from
rollback_configs/directory.
- Scans running containers for Compose labels.
- Marks Compose-managed containers.
- Prints contents of
summary.log(updates performed).
- Lists exposed ports for each container using
docker port.
- Saves
docker inspectoutput for each container torollback_configs/.
log.txt: Logs updates to standard containers.dockerupdatelog.txt: Logs Dockerfile image updates.summary.log: Global summary of all updates.network_map.txt: Container network connection overview.rollback_configs/: Stores fulldocker inspectJSONs for rollback.
- Swarm services are updated in-place (no deletion or downtime).
- Standalone container updates are not destructive if rollback is used.
- Docker Compose containers are detected but not updated directly — use
docker-compose pull && up -dmanually.
- Automated rollback execution
- Image digest/version comparison
- Email or webhook alerts
- YAML export support
- Automated scheduling via cron
MIT License. Modify and use freely with proper safety precautions.