Essential Docker Commands for Daily Operations & Deployment
📌 Essential Docker Commands for Daily Operations & Deployment
This is a practical checklist I follow for daily Docker operations, image management, and frontend deployment.
🔹 1. Daily Monitoring & Inspection
View running processes inside a container
docker top <container_name>
Example:
docker top inventory-frontend
🔹 2. Build Frontend Image (Artifact Creation)
Build Docker image from frontend source
docker build -t inventory-frontend:prod1 ./frontend
This creates a versioned frontend image that can be reused across environments.
🔹 3. Save Image as Artifact (For Transfer / Backup)
Export Docker image to a tar file
docker save inventory-frontend:prod1 -o inventory-frontend-prod1.tar
Useful for:
Moving images between servers
Offline deployments
Audit backups
🔹 4. Load Image on Target Server
Import image from tar file
docker load < inventory-frontend-prod1.tar
🔹 5. Stop & Remove Existing Frontend Container
Stop running container
docker stop inventory-frontend
Remove container
docker rm inventory-frontend
This ensures the new image is used cleanly.
🔹 6. Start Only Frontend Service Using Docker Compose
Bring up only the frontend service
docker compose -f docker-compose.prod.yml up -d frontend
✔ Backend and database remain untouched
✔ Safe for production updates
🔹 7. Restart Container (If Required)
Restart a running container
docker restart <container_name>
Example:
docker restart inventory-frontend
🔹 8. Remove Old / Unused Docker Images
Remove a specific image
docker rmi <image_name>
Example:
docker rmi inventory-frontend:prod1
Remove all unused images (safe cleanup)
docker image prune
For aggressive cleanup (unused images only):
docker image prune -a
🔹 9. Quick Daily Cleanup (Recommended)
docker ps
docker images
docker image prune
Keeps the system clean and avoids disk-space issues.
🧠Summary Workflow (Production-Safe)
Build image
Save as artifact
Load on server
Stop old container
Remove old container
Start frontend only
Clean unused images
✅ Final Tip (Best Practice)
Images are immutable → version them (
prod1,prod2, etc.)Containers are disposable → remove & recreate
Build React outside Docker → serve via Nginx
Use docker-compose service targeting for safe updates
Comments
Post a Comment