Docker Container Commands
docker container → Manage containers
docker container create → Create a new container
docker container start → Start one or more stopped containers
docker container run → Create and run a new container from an image
docker container exec → Execute a command in a running container
docker container attach → Attach local input/output streams to a running container
docker container rename → Rename a container
docker container update → Update configuration of one or more containers
docker container ls → List containers
docker container inspect → Display detailed information on one or more containers
docker container logs → Fetch the logs of a container
docker container stats → Live stream of resource usage
docker container top → Display running processes
docker container port → List port mappings
docker container diff → Inspect filesystem changes
docker container pause → Pause all processes within one or more containers
docker container unpause → Unpause all processes within one or more containers
docker container restart → Restart one or more containers
docker container stop → Stop containers gracefully
docker container kill → Kill one or more running containers
docker container wait → Block until containers stop, then print exit codes
docker container cp → Copy files/folders between container and host
docker container export → Export container filesystem as a tar archive
docker container rm → Remove one or more containers
docker container prune → Remove all stopped containers
docker container commit → Create a new image from container changes
Docker Containers
docker container → Manage containersUsage : docker containerCreation & Startup
docker container create
docker container create → Create a new containerUsage : docker container create [OPTIONS] IMAGE [COMMAND] [ARG...]
Aliases : docker createDescription:
- Makes a new container from an image, sets up a writable layer, prints its ID, but doesn’t start it.
- Unlike
docker run -d, the container stays in created state until you start it manually. Handy for pre‑configuring containers before launch.
docker container create --name myapp -p 8080:80 nginxCreates a container named myapp from the nginx image, mapped to port 8080, but doesn’t start it yet.
- Key takeaway: Use
docker container createwhen you want to prepare a container ahead of time without running it immediately.

docker container run
docker container run → Create and run a new container from an imageUsage : docker container run [OPTIONS] IMAGE [COMMAND] [ARG...]
Aliases : docker runDescription:
- Creates and starts a new container (pulls image if missing), runs command immediately. Combines
docker create+docker start. - Use
docker startto restart stopped containers, anddocker ps -ato list all. Ideal for quick tests or launching services.
# Run a new container from nginx image
docker run -d --name web nginx
# Run interactively with a shell
docker run -it ubuntu bash
# Map a port and run in background
docker run -d -p 8080:80 nginxKey takeaway: docker run is the launch command, creating and starting a container in one step, pulling the image if needed.

docker container start
docker container start → Start one or more stopped containersUsage : docker container start [OPTIONS] CONTAINER [CONTAINER...]
Aliases : docker startDescription:
- Runs a container from Created/Stopped state. Used after
docker createto launch prepared containers. For immediatecreate+run, usedocker run. - Best for reusing containers without rebuilding. Add
-a -ito attach and interact as if newly launched.
# Start a stopped container by name
docker container start myapp
# Start and attach to it interactively
docker container start -ai myappKey takeaway: docker container start is the switch that powers up stopped containers, with options to attach, interact, or even restore from checkpoints.

Execution & Interaction
docker container exec
docker container exec → Execute a command in a running containerUsage : docker container exec [OPTIONS] CONTAINER COMMAND [ARG...]
Aliases : docker execDescription:
- Runs a command inside a running container (only while PID 1 is alive). Doesn’t auto‑restart if the container restarts.
- Commands run in the default working directory and must be valid executables.
🐞 docker debug (New Alternative)
- Opens a debug shell in any container/image, even slim ones without a shell.
- Lets you bring custom tools, making it more flexible than exec since it doesn’t rely on pre‑installed utilities.
# Open an interactive shell inside a running container
docker exec -it my_container /bin/bash
# Run a single command
docker exec my_container ls /appKey takeaway:
- Use
docker execfor quick commands inside running containers. - Use
docker debugwhen you need a full debugging environment with tools, even in minimal images.

docker container attach
docker container attach → Attach local standard input, output, and error streams to a running containerUsage : docker container attach [OPTIONS] CONTAINER
Aliases : docker attachDescription:
- Connects your terminal (STDIN/STDOUT/STDERR) to a running container, showing its ENTRYPOINT/CMD output and allowing interaction. Multiple sessions can attach.
- Stop:
CTRL‑C→ sends SIGINT (or SIGKILL if--sig-proxy=false). - Detach:
CTRL‑PCTRL‑Q(only if started with-i -t). - PID 1 processes may ignore signals unless coded.
- No
STDINredirection with TTY. Uses ~1MB buffer; heavy output may lag. - For performance‑critical apps, use docker logs instead.
# Attach to a running container by name
docker container attach myapp
# Attach to a container by ID
docker container attach 123abc456defKey takeaway: Use docker container attach when you want to interactively connect to a running container’s main process. For log viewing or high‑output apps, use docker logs instead.

docker container rename
docker container rename → Rename a containerUsage : docker container rename CONTAINER NEW_NAME
Aliases : docker renameDescription:
- Changes a container’s name without restart. Names must be unique.
- Only the human‑readable name changes - ID, config, and data stay the same.
- Useful for organizing containers in multi‑service projects or fixing unnamed ones.
# Rename a container called "web" to "frontend"
docker container rename web frontendKey takeaway: docker container rename is a quick way to give containers meaningful names so they’re easier to manage and identify.

docker container update
docker container update → Update configuration of one or more containersUsage : docker container update [OPTIONS] CONTAINER [CONTAINER...]
Aliases : docker updateDescription:
- Dynamically changes container configuration (e.g., resource limits) for one or more containers.
- Works on running or stopped containers, except
--kernel-memory(restricted on kernels <4.6). Not supported on Windows containers. - Changes apply instantly without restart - ideal for fine‑tuning resource usage in production.
# Limit memory and CPU for a running container
docker container update --memory 512m --cpus 1 myapp
# Apply limits to multiple containers at once
docker container update --cpu-shares 512 web1 db1 cache1
Key takeaway: docker container update lets you adjust resource limits on the fly, keeping containers efficient and preventing them from overwhelming the host.

Monitoring & Inspection
docker container ls
docker container ls → List containersUsage : docker container ls [OPTIONS]
Aliases : docker container list, docker container ps, docker psDescription:
- Lists running containers with ID, image, command, status, ports, and names.
- Use
-ato show all (including stopped). Commonly paired with stop, rm, or inspect for management.
# List running containers
docker container ls
# List all containers, including stopped
docker container ls -a
# Show only container IDs
docker container ls -q
# Filter by status
docker container ls --filter status=exited
Key takeaway: docker container ls is the go‑to command for viewing containers, with options to show all, filter, or format the output.

docker container inspect
docker container inspect → Display detailed information on one or more containersUsage : docker container inspect [OPTIONS] CONTAINER [CONTAINER...]
Aliases : NADescription:
- Outputs detailed container info in
JSON(config, networking, volumes, env vars, runtime state). Works on running and stopped containers. - Use
--formatto filter fields. Commonly paired withjqfor parsing. Great for troubleshooting, auditing, or programmatic detail extraction.
# Inspect a single container
docker container inspect myapp
# Inspect multiple containers
docker container inspect web1 db1
# Extract only the IP address using a format string
docker container inspect -f '{{ .NetworkSettings.IPAddress }}' myapp
Key takeaway: docker container inspect is the deep dive command for viewing every detail about a container’s configuration and state, with flexible formatting for targeted information.

docker container logs
docker container logs → Fetch the logs of a containerUsage : docker container logs [OPTIONS] CONTAINER
Aliases : docker logsDescription:
- Shows container logs available at execution time. Useful for debugging, monitoring, and activity checks. Output depends on the logging driver.
- For performance‑critical apps, configure drivers carefully to reduce overhead. Often paired with monitoring tools for real‑time visibility.
# Fetch logs from a container
docker container logs myapp
# Stream logs live
docker container logs -f myapp
# Show last 50 lines
docker container logs --tail 50 myapp
# Show logs since 10 minutes ago
docker container logs --since 10m myapp
# Show logs with timestamps
docker container logs -t myapp
Key takeaway: docker container logs is the go‑to command for viewing and streaming container output, with flexible options for filtering, timestamps, and continuous monitoring.

docker container stats
docker container stats → Display a live stream of container(s) resource usage statisticsUsage : docker container stats [OPTIONS] [CONTAINER...]
Aliases : docker statsDescription:
- Displays live metrics: CPU, memory, network I/O, block I/O, and process counts.
- You can target specific containers by name/ID. Stopped containers return no data. For deeper metrics, use Docker API /containers/(id)/stats.
# Show live stats for all running containers
docker container stats
# Show stats for specific containers
docker container stats web1 db1
Key takeaway
It is the real‑time monitoring tool for container resource usage, helping you track performance and detect unusual behavior like excessive memory cache or thread creation.

docker container top
docker container top → Dislay the running processes of a conntainerUsage : docker container top CONTAINER [ps OPTIONS]
Aliases : docker topDescription:
- Lists active processes inside a container (like Linux ps: PID, user, command).
- Useful for real‑time debugging and seeing which processes are running. Output format depends on OS and process table.
# Show processes in a container named "myapp"
docker container top myapp
# Show processes using container ID
docker container top 123abc456def
docker container port
docker container port → List port mappings or a specific mapping for the containerUsage : docker container port CONTAINER [PRIVATE_PORT[/PROTO]]
Aliases : docker portDescription:
- Shows active processes inside a container (like Linux ps/top). Useful for debugging idle/misbehaving containers and checking running tasks.
- Output depends on the container’s OS. Often paired with docker stats for monitoring.
# Show processes running in a container named "web1"
docker container top web1
# Show processes with custom arguments (like ps options)
docker container top web1 -o pid,comm
Key takeaway: docker container top is the quick inspection tool for viewing active processes inside a container, helping you understand what’s running at any given time.

docker container diff
docker container diff → Inspect changes to files or directories on a container's filesystemUsage : docker container diff CONTAINER
Aliases : docker diffDescription:
- Lists filesystem changes in a container since creation (relative to the image layer). Shows added, modified, or deleted files with simple symbols.
- Works by container name or ID. Excludes mounted volumes - only tracks the writable layer. Useful for debugging or auditing modifications.
# Show changes in a container named "myapp"
docker container diff myapp
# Show changes using container ID
docker container diff 123abc456def
Key takeaway: docker container diff is the change tracker for containers, showing added, deleted, or modified files since creation.

Process Control
docker container pause
docker container pause → Pause all processes within one or more containersUsage : docker container pause CONTAINER [CONTAINER...]
Aliases : docker pauseDescription:
- Freezes all processes in one or more containers (Linux uses freezer cgroup). On Windows, works only with Hyper‑V containers.
- Does not stop or kill - just suspends until docker unpause. Useful for temporarily halting activity without termination.
# Pause a single container
docker container pause myapp
# Pause multiple containers
docker container pause web1 db1
Key takeaway: docker container pause is the freeze button for containers, suspending all processes invisibly until you unpause them.

docker container unpause
docker container unpause → Unpause all processes within one or more containersUsage : docker container unpause CONTAINER [CONTAINER...]
Aliases : docker unpauseDescription:
- Resumes all processes in paused containers. On Linux, uses freezer cgroup (transparent to the container).
- Complements docker pause and only works on currently paused containers. Useful for halting/resuming workloads without restart.
- On Windows, supported only for Hyper‑V containers.
# Unpause a single container
docker container unpause myapp
# Unpause multiple containers
docker container unpause web1 db1
Key takeaway: docker container unpause is the resume button for containers, restoring all processes that were frozen with pause.

docker container restart
docker container restart → Restart one or more containersUsage : docker container restart [OPTIONS] CONTAINER [CONTAINER...]
Aliases : docker restartDescription:
- Stops and then starts containers in one step. Works on running or stopped containers, reusing the same config and filesystem (no rebuild).
- Useful for applying config changes or fixing misbehaving containers. Timeout option controls how long Docker waits for graceful shutdown before forcing termination.
# Restart a single container
docker container restart myapp
# Restart multiple containers
docker container restart web1 db1 cache1
# Restart with a custom timeout
docker container restart -t 5 myapp
Key takeaway: docker container restart is the reset button for containers, stopping and starting them in one step to refresh their state.

docker container stop
docker container stop → Remove one or more containersUsage : docker container stop [OPTIONS] CONTAINER [CONTAINER...]
Aliases : docker stopDescription:
- Gracefully stops running containers. Sends SIGTERM first, then SIGKILL if not exited within the grace period.
- Stop signal can be customized via STOPSIGNAL in Dockerfile or --stop-signal in run/create. Stopping doesn’t remove the container - it can be restarted later.
- Important for apps needing cleanup (e.g., databases). Use docker kill for immediate termination.
# Stop a single container
docker container stop myapp
# Stop multiple containers
docker container stop web1 db1 cache1
# Stop with a custom timeout
docker container stop -t 20 myapp
Key takeaway: docker container stop is the graceful shutdown command, giving containers time to exit cleanly before forcing termination.

docker container kill
docker container kill → Kill one or more running containersUsage : docker container kill [OPTIONS] CONTAINER [CONTAINER...]
Aliases : docker killDescription:
- Immediately terminates one or more containers. By default sends SIGKILL (forceful stop), but you can specify another signal with
--signal. - Containers can be targeted by ID, ID prefix, or name. Faster and more forceful than docker stop, but bypasses cleanup routines - so use with caution.
# Kill a container with the default SIGKILL
docker container kill myapp
# Kill multiple containers
docker container kill web1 db1
# Send a custom signal (SIGINT)
docker container kill --signal=SIGINT myapp
# Send a signal by number (2 = SIGINT)
docker container kill --signal=2 myapp
Key takeaway: docker container kill is the immediate termination command, sending signals directly to container processes, with SIGKILL as the default.

docker container wait
docker container wait → Block until one or more containers stop, then print their exit codesUsage : docker container wait CONTAINER [CONTAINER...]
Aliases : docker waitDescription:
- Blocks until specified containers stop. Then prints their exit codes:
0→ success |non‑zero→ error/abnormal termination
Useful in scripting/automation (e.g., CI/CD) to synchronize tasks. Complements docker run or docker stop when controlled sequencing is needed.
# Wait for a single container to stop
docker container wait myapp
# Wait for multiple containers
docker container wait web1 db1
Key takeaway: docker container wait is the synchronization command, pausing until containers stop and reporting their exit codes for automation or debugging.

File & Data Operations
docker container cp
docker container cp → Copy files/folders between a container and the local filesystemUsage : docker container cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|- docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
Aliases : docker cpDescription:
- Copies files/directories between container and host, both directions.
- Works on running or stopped containers. Supports tar streaming with - for source/dest. Behaves like
cp -a: recursive, preserves permissions. - Great for moving configs, logs, or assets in/out of containers without rebuilding images.
# Copy a file from container to local machine
docker cp myapp:/var/log/app.log ./app.log
# Copy a local file into a container
docker cp ./config.yml myapp:/etc/config.yml
# Copy a directory from container to local machine
docker cp myapp:/usr/share/data ./data
# Stream a tar archive from container to local machine
docker cp myapp:/var/log - > logs.tar
Key takeaway: docker cp is the file transfer tool for moving data between containers and your local system, with options for ownership and symlink handling.

docker container export
docker container export → Export a container's filesystem as a tar archiveUsage : docker container export [OPTIONS] CONTAINER
Aliases : docker exportDescription:
- Exports a container’s filesystem as a tar archive. Excludes mounted volumes (only the underlying directory is exported).
- Works for saving or migrating a container snapshot. Captures the writable layer of the container, not external data.
# Export a container’s filesystem to a tar file
docker container export myapp > myapp.tar
# Export using container ID
docker container export 123abc456def > backup.tar
Key takeaway: docker container export is the snapshot tool for capturing a container’s filesystem, but volumes must be backed up separately.

Cleanup & Removal
docker container rm
docker container rm → Remove one or more containerUsage : docker container rm [OPTIONS] CONTAINER [CONTAINER...]
Aliases : docker container remove, docker rmDescription:
- Removes one or more containers (by name or ID). By default, only stopped containers can be removed.
- Use -f to force removal of running containers (terminates processes immediately).
- Removing a container does not delete its image. Use docker container prune to remove all stopped containers at once.
# Remove a single stopped container
docker container rm myapp
# Remove multiple containers at once
docker container rm web1 db1 cache1
# Force remove a running container
docker container rm -f myapp
# Remove a container and its anonymous volumes
docker container rm -v myapp
Key takeaway: docker container rm is the cleanup command for removing containers you no longer need, with options to force removal or also delete attached volumes.

docker container prune
docker container prune → Remove all stopped containersUsage : docker container prune [OPTIONS]
Aliases : NADescription:
- Removes all stopped containers at once. Frees system resources and keeps environment tidy.
- Prompts for confirmation by default. Running containers are unaffected.
- Does not remove images, volumes, or networks (use other prune commands for those). Handy after testing/dev sessions with many stopped containers.
# Remove all stopped containers with confirmation
docker container prune
# Remove all stopped containers without confirmation
docker container prune -f
Key takeaway: docker container prune is the bulk cleanup command for stopped containers, saving time and keeping your Docker host uncluttered.

Image Management
docker container commit
docker container commit → Create a new image from a container's changesUsage : docker container commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Aliases : docker commitDescription:
- Saves a container’s current state as a new image. Useful for debugging (preserve changes from interactive sessions) or exporting environments.
- Captures only the container’s writable layer (mounted volumes excluded).
- By default, container is paused during commit to avoid corruption (--pause=false disables). You can add Dockerfile instructions with --change.
- Best practice: use commits for experiments/debugging, but rely on Dockerfiles for reproducible builds.
# Commit changes from a container into a new image
docker container commit myapp myimage:debug
# Commit without pausing the container
docker container commit --pause=false myapp myimage:live
# Commit and apply a new CMD instruction
docker container commit --change='CMD ["nginx", "-g", "daemon off;"]' myapp myimage:web
Key takeaway: docker container commit lets you turn a running container’s state into a reusable image, with options to pause safely and apply new instructions.

Follow for Engineering and Tech - Tips, Tricks, Roadmaps, Resources, Networking, Motivation, Guidance, and Cool Stuff ♥
