Container Deployment
Container Lifecycle Management
Container deployment involves managing the entire lifecycle of Docker containers, from creation to termination, ensuring efficient and reliable application execution.
graph LR
A[Image Pull] --> B[Container Creation]
B --> C[Container Start]
C --> D[Running State]
D --> E[Container Stop]
E --> F[Container Remove]
Container Deployment Strategies
Strategy |
Description |
Single Container |
Basic deployment of individual containers |
Multi-Container |
Deploying interconnected containers |
Scaling |
Horizontal scaling of container instances |
Rolling Updates |
Gradual container replacement |
Basic Container Deployment Commands
## Run a simple container
docker run -d --name web-app nginx:latest
## Run container with port mapping
docker run -p 8080:80 -d nginx:latest
## Run container with environment variables
docker run -e DATABASE_URL=postgres://user:pass@host/db -d myapp:v1
Advanced Deployment Options
## Container resource limitations
docker run --cpus=2 --memory=1g nginx:latest
## Volume mounting
docker run -v /host/path:/container/path nginx:latest
## Network configuration
docker run --network=custom_network nginx:latest
Container Management Commands
## List running containers
docker ps
## List all containers
docker ps -a
## Stop a container
docker stop web-app
## Remove a container
docker rm web-app
## Restart a container
docker restart web-app
Container Orchestration Basics
## Docker Compose deployment
docker-compose up -d
## Scaling containers
docker-compose scale web=3
## Checking service status
docker-compose ps
## Real-time container resource usage
docker stats
## Container logs
docker logs web-app
## Inspect container details
docker inspect web-app