Run Container with Limited Resources
# Limit CPU usage to 50% and memory to 256MB
docker run -d --name limited_container --cpus=".5" --memory="256m" myimage
Inspect Container Disk Usage
# Check disk usage of files in a running container
docker exec -it container_name du -h /path/to/dir
Optimize Docker Images with Multi-Stage Builds
# Use a multi-stage build to reduce image size
FROM golang:1.19 AS builder
WORKDIR /app
COPY . .
RUN go build -o main .

FROM alpine:latest
WORKDIR /root/
COPY --from=builder /app/main .
CMD ["./main"]
Clean Up Unused Docker Resources
# Remove unused images, containers, networks, and volumes
docker system prune -a
Log Container Resource Usage
# Monitor resource usage statistics for containers
docker stats