Advanced Settings
Container Resource Management
CPU and Memory Constraints
## Limit CPU usage
docker run --cpus=0.5 ubuntu:22.04
## Set memory constraints
docker run --memory=512m ubuntu:22.04
Network Configuration
graph TD
A[Docker Network Modes] --> B[Bridge]
A --> C[Host]
A --> D[None]
A --> E[Custom Network]
Advanced Networking
## Create custom network
docker network create --driver bridge custom_network
## Connect container to specific network
docker run --network=custom_network ubuntu:22.04
Volume and Storage Management
Storage Type |
Description |
Use Case |
Bind Mounts |
Direct host directory mapping |
Development |
Named Volumes |
Managed by Docker |
Persistent data |
Tmpfs Mounts |
Temporary in-memory storage |
Sensitive data |
Complex Volume Configurations
## Create named volume
docker volume create app_data
## Mount volume with specific permissions
docker run -v app_data:/app:ro ubuntu:22.04
Security Configurations
Container Capabilities
## Drop unnecessary capabilities
docker run --cap-drop=ALL --cap-add=NET_BIND_SERVICE ubuntu:22.04
Advanced Runtime Parameters
Parameter |
Function |
Example |
--read-only |
Immutable container filesystem |
docker run --read-only |
--security-opt |
Custom security profiles |
docker run --security-opt |
--init |
Manage process lifecycle |
docker run --init |
Logging and Monitoring
## Advanced logging configuration
docker run --log-driver=json-file \
--log-opt max-size=10m \
--log-opt max-file=3 \
ubuntu:22.04
Container Orchestration Considerations
graph TD
A[Container Orchestration] --> B[Scaling]
A --> C[Health Checks]
A --> D[Rolling Updates]
A --> E[Service Discovery]
LabEx Pro Tip
At LabEx, we emphasize understanding advanced Docker settings to optimize container performance, security, and manageability.
- Use multi-stage builds
- Minimize image layers
- Implement efficient caching strategies
- Use lightweight base images
Debugging and Troubleshooting
## Advanced container inspection
docker inspect --format='{{.State.Pid}}' container_name
## Real-time container stats
docker stats container_name
Best Practices
- Implement least privilege principle
- Use read-only filesystems when possible
- Regularly update base images
- Monitor container resource utilization
- Implement comprehensive logging