🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

10 Docker Commands Every Developer and Admin Should Know in 2026

10 Docker Commands Every Developer and Admin Should Know in 2026

Docker has become the standard for application packaging and deployment. Whether you are a developer building microservices or a system administrator managing production containers, mastering these 10 Docker commands will significantly boost your productivity.

1. docker compose up --build --force-recreate

When developing with Docker Compose, you often need to rebuild images and recreate containers after code changes. This single command handles both:

# Rebuild images and recreate all containers
docker compose up --build --force-recreate -d

# Only rebuild specific service
docker compose up --build --force-recreate -d webapp

The --force-recreate flag ensures containers are recreated even if configuration hasn't changed, which is essential when debugging environment-related issues.

2. docker exec -it [container] /bin/sh

Access a running container's shell for debugging:

# Access container with bash
docker exec -it my-webapp /bin/bash

# For Alpine-based images (no bash)
docker exec -it my-webapp /bin/sh

# Run a specific command without interactive shell
docker exec my-webapp cat /etc/nginx/nginx.conf

3. docker logs --follow --tail 100

Tail container logs in real-time, showing the last 100 lines:

# Follow logs with timestamp
docker logs --follow --tail 100 --timestamps my-webapp

# Filter logs by time range
docker logs --since "2026-03-01T08:00:00" my-webapp

# Combine with grep for filtering
docker logs my-webapp 2>&1 | grep -i error

4. docker system df

Check Docker disk usage to identify space-consuming resources:

# Show disk usage summary
docker system df

# Verbose output with individual items
docker system df -v

This is invaluable when your server runs low on disk space. Follow up with docker system prune to reclaim space.

5. docker inspect --format

Extract specific information from containers using Go templates:

# Get container IP address
docker inspect --format "{{.NetworkSettings.IPAddress}}" my-webapp

# Get all environment variables
docker inspect --format "{{.Config.Env}}" my-webapp

# Get mounted volumes
docker inspect --format "{{.Mounts}}" my-webapp

# Get container health status
docker inspect --format "{{.State.Health.Status}}" my-webapp

6. docker stats --no-stream

Get a snapshot of resource usage across all running containers:

# One-time snapshot of all containers
docker stats --no-stream

# Format output for scripting
docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}"

7. docker network inspect

Debug networking issues between containers:

# List all networks
docker network ls

# Inspect a specific network
docker network inspect bridge

# Find which containers are on a network
docker network inspect my-network --format "{{range .Containers}}{{.Name}} {{end}}"

8. docker cp

Copy files between host and container without rebuilding:

# Copy from container to host
docker cp my-webapp:/var/log/nginx/error.log ./error.log

# Copy from host to container
docker cp ./config.json my-webapp:/app/config.json

9. docker build --target

Use multi-stage build targets for different environments:

# Build only the development stage
docker build --target development -t myapp:dev .

# Build the production stage
docker build --target production -t myapp:prod .

# Build with build arguments
docker build --build-arg NODE_ENV=production -t myapp:prod .

10. docker compose config

Validate and view the resolved Docker Compose configuration:

# Validate and display merged config
docker compose config

# Check for errors without output
docker compose config --quiet

# Show only service names
docker compose config --services

Bonus: Clean Up Everything

# Remove all stopped containers, unused networks, dangling images
docker system prune -a --volumes

# Remove specific unused images
docker image prune -a --filter "until=720h"

Master these commands and your daily Docker workflow will become significantly faster and more efficient.

Dive Deeper

Share this article:
Dargslan Editorial Team (Dargslan)
About the Author

Dargslan Editorial Team (Dargslan)

Collective of Software Developers, System Administrators, DevOps Engineers, and IT Authors

Dargslan is an independent technology publishing collective formed by experienced software developers, system administrators, and IT specialists.

The Dargslan editorial team works collaboratively to create practical, hands-on technology books focused on real-world use cases. Each publication is developed, reviewed, and...

Programming Languages Linux Administration Web Development Cybersecurity Networking

Stay Updated

Subscribe to our newsletter for the latest tutorials, tips, and exclusive offers.