π¦ ClawHub
Docker Essentials
by @arnarsson
Essential Docker commands and workflows for container management, image operations, and debugging.
TERMINAL
clawhub install docker-essentialsπ About This Skill
name: docker-essentials description: Essential Docker commands and workflows for container management, image operations, and debugging. homepage: https://docs.docker.com/ metadata: {"clawdbot":{"emoji":"π³","requires":{"bins":["docker"]}}}
Docker Essentials
Essential Docker commands for container and image management.
Container Lifecycle
Running containers
# Run container from image
docker run nginxRun in background (detached)
docker run -d nginxRun with name
docker run --name my-nginx -d nginxRun with port mapping
docker run -p 8080:80 -d nginxRun with environment variables
docker run -e MY_VAR=value -d appRun with volume mount
docker run -v /host/path:/container/path -d appRun with auto-remove on exit
docker run --rm alpine echo "Hello"Interactive terminal
docker run -it ubuntu bash
Managing containers
# List running containers
docker psList all containers (including stopped)
docker ps -aStop container
docker stop container_nameStart stopped container
docker start container_nameRestart container
docker restart container_nameRemove container
docker rm container_nameForce remove running container
docker rm -f container_nameRemove all stopped containers
docker container prune
Container Inspection & Debugging
Viewing logs
# Show logs
docker logs container_nameFollow logs (like tail -f)
docker logs -f container_nameLast 100 lines
docker logs --tail 100 container_nameLogs with timestamps
docker logs -t container_name
Executing commands
# Execute command in running container
docker exec container_name ls -laInteractive shell
docker exec -it container_name bashExecute as specific user
docker exec -u root -it container_name bashExecute with environment variable
docker exec -e VAR=value container_name env
Inspection
# Inspect container details
docker inspect container_nameGet specific field (JSON path)
docker inspect -f '{{.NetworkSettings.IPAddress}}' container_nameView container stats
docker statsView specific container stats
docker stats container_nameView processes in container
docker top container_name
Image Management
Building images
# Build from Dockerfile
docker build -t myapp:1.0 .Build with custom Dockerfile
docker build -f Dockerfile.dev -t myapp:dev .Build with build args
docker build --build-arg VERSION=1.0 -t myapp .Build without cache
docker build --no-cache -t myapp .
Managing images
# List images
docker imagesPull image from registry
docker pull nginx:latestTag image
docker tag myapp:1.0 myapp:latestPush to registry
docker push myrepo/myapp:1.0Remove image
docker rmi image_nameRemove unused images
docker image pruneRemove all unused images
docker image prune -a
Docker Compose
Basic operations
# Start services
docker-compose upStart in background
docker-compose up -dStop services
docker-compose downStop and remove volumes
docker-compose down -vView logs
docker-compose logsFollow logs for specific service
docker-compose logs -f webScale service
docker-compose up -d --scale web=3
Service management
# List services
docker-compose psExecute command in service
docker-compose exec web bashRestart service
docker-compose restart webRebuild service
docker-compose build webRebuild and restart
docker-compose up -d --build
Networking
# List networks
docker network lsCreate network
docker network create mynetworkConnect container to network
docker network connect mynetwork container_nameDisconnect from network
docker network disconnect mynetwork container_nameInspect network
docker network inspect mynetworkRemove network
docker network rm mynetwork
Volumes
# List volumes
docker volume lsCreate volume
docker volume create myvolumeInspect volume
docker volume inspect myvolumeRemove volume
docker volume rm myvolumeRemove unused volumes
docker volume pruneRun with volume
docker run -v myvolume:/data -d app
System Management
# View disk usage
docker system dfClean up everything unused
docker system pruneClean up including unused images
docker system prune -aClean up including volumes
docker system prune --volumesShow Docker info
docker infoShow Docker version
docker version
Common Workflows
Development container:
docker run -it --rm \
-v $(pwd):/app \
-w /app \
-p 3000:3000 \
node:18 \
npm run dev
Database container:
docker run -d \
--name postgres \
-e POSTGRES_PASSWORD=secret \
-e POSTGRES_DB=mydb \
-v postgres-data:/var/lib/postgresql/data \
-p 5432:5432 \
postgres:15
Quick debugging:
# Shell into running container
docker exec -it container_name shCopy file from container
docker cp container_name:/path/to/file ./local/pathCopy file to container
docker cp ./local/file container_name:/path/in/container
Multi-stage build:
# Dockerfile
FROM node:18 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run buildFROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
Useful Flags
docker run flags:
-d: Detached mode (background)-it: Interactive terminal-p: Port mapping (host:container)-v: Volume mount-e: Environment variable--name: Container name--rm: Auto-remove on exit--network: Connect to networkdocker exec flags:
-it: Interactive terminal-u: User-w: Working directoryTips
.dockerignore to exclude files from build contextRUN commands in Dockerfile to reduce layers--rm for one-off containersdocker-compose for multi-container appsdocker system pruneDocumentation
Official docs: https://docs.docker.com/ Dockerfile reference: https://docs.docker.com/engine/reference/builder/ Compose file reference: https://docs.docker.com/compose/compose-file/
π Tips & Best Practices
.dockerignore to exclude files from build contextRUN commands in Dockerfile to reduce layers--rm for one-off containersdocker-compose for multi-container appsdocker system prune