Managing containerized microservices requires understanding the state transitions of Docker containers. From running detached background instances to stopping gracefully and purging exited containers, mastering CLI lifecycle commands is fundamental to container orchestration.

Docker Container Lifecycle Command Reference

Docker CLI Commandsbash
# 1. Create and run a new background container
docker run -d --name web_server -p 8080:80 nginx:latest
 
# 2. List running containers
docker ps
 
# 3. Stop running container gracefully (SIGTERM -> SIGKILL)
docker stop web_server
 
# 4. Start stopped container
docker start web_server
 
# 5. Remove stopped container instance
docker rm web_server
 
# 6. Force remove running container immediately
docker rm -f web_server