Container LifecycleIntermediate
1Question 1 of 1
bashHow does the Container Lifecycle work (create, start, stop, kill, rm)?
Explanation & Concept
Container lifecycle commands: • `docker create`: Prepares a container from an image without starting it. • `docker start`: Starts a stopped container. • `docker stop`: Sends `SIGTERM` to allow graceful shutdown within a 10s grace period, followed by `SIGKILL`. • `docker kill`: Immediately sends `SIGKILL` for instant termination. • `docker rm`: Deletes the container's read-write layer from disk.
Code Example
bash
# Graceful stop with custom timeout
docker stop -t 30 my_worker_container
# Remove stopped containers and unused images
docker system prune -a --volumesHow It Works & Key Takeaways
Applications should catch `SIGTERM` in their code to finish inflight requests and close database connections cleanly before exiting.
Mock Test · 1 Questions · Optional
Ready for Docker Networking Modes?
Take a quick test to evaluate yourself, or move straight to the next module.
Intermediate1 questions