Skip to content

Instantly share code, notes, and snippets.

@TrQ-Hoan
Created May 24, 2025 02:05
Show Gist options
  • Select an option

  • Save TrQ-Hoan/28e2b14bc6cc7b6683fcd7a51931f2ab to your computer and use it in GitHub Desktop.

Select an option

Save TrQ-Hoan/28e2b14bc6cc7b6683fcd7a51931f2ab to your computer and use it in GitHub Desktop.
Update docker
#!/bin/bash
# Check if docker-compose.yml exists in the current directory
if [ ! -f "docker-compose.yml" ]; then
echo "Error: docker-compose.yml not found in the current directory."
exit 1
fi
# Pull Docker images (with or without arguments)
if [ $# -gt 0 ]; then
echo "Pulling Docker images for services: $@"
docker compose pull "$@"
else
echo "Pulling all Docker images..."
docker compose pull
fi
# Start services (with or without arguments)
if [ $# -gt 0 ]; then
echo "Starting services: $@"
docker compose up -d --force-recreate "$@"
else
echo "Starting all services..."
docker compose up -d --force-recreate
fi
# Ask user if they want to clean up unused images
read -p "Do you want to clean up unused Docker images? (y/n): " answer
if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then
echo "Cleaning up unused Docker images..."
docker image prune -f
else
echo "Skipping cleanup."
fi
echo "Update completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment