Skip to content

Latest commit

 

History

History
281 lines (211 loc) · 6.99 KB

File metadata and controls

281 lines (211 loc) · 6.99 KB

Docker Containers

Containers are running instances of images. These commands allow you to manage their lifecycle.

List running containers

View all currently active containers. #ps #ls

docker ps

List all containers

View all containers, including stopped ones. #ps-all #all

docker ps -a

Run a container

Create and start a new container from an image. #run #start-new

docker run $run_opts $image

Execute command in container

Run a new command in an already running container. Often used to drop into a shell. #shell #bash #sh #attach

docker exec -it $container_running /bin/sh

Start a stopped container

Start a container that has been stopped. #boot #up

docker start $container_all

Stop a running container

Gracefully stop a running container. #halt #shutdown

docker stop $container_running

Restart a container

Stop and then start a container. #reboot

docker restart $container_running

Kill a container

Forcefully terminate a running container immediately. #nuke #destroy #sigkill

docker kill $container_running

Remove a container

Delete a stopped container. Use --force to delete a running one. #rm #delete #purge

docker rm $rm_opts $container_all

View container logs

Fetch the logs of a container. Useful for debugging. #logs #tail #debug

docker logs -f $container_all

Inspect a container

Return low-level JSON information on a Docker container. #details #ip #json

docker inspect $container_all

View container stats

Display a live stream of container resource usage statistics (CPU, RAM). #top #htop #usage

docker stats

Execute command as ROOT (Admin/Debug)

Execute a command in a running container as the root user. Excellent for debugging permission issues or administering the container. #root #exec-root #admin #uid0

docker exec -u 0 -it $container_running /bin/bash

Privileged Container (Host Administration)

Run a highly privileged container that mounts the host's entire root filesystem. This is useful for emergency debugging or administering the underlying Docker host. #admin #debug #host-mount #recovery

docker run --privileged --net=host --pid=host -v /:/mnt/root -it $image /bin/bash

Commit container to image

Create a new image from a container's changes. Useful if you've manually installed packages and want to save the state. #save #snapshot #backup

docker commit $container_all $new_image_name

Export container filesystem

Export a container's filesystem as a tar archive. #export #tar #extract

docker export -o $export_file $container_all

Copy files from/to container

Copy files or folders between a container and the local filesystem. #cp #copy #extract

docker cp $direction

Inspect filesystem changes

Inspect changes to files or directories on a container's filesystem since it was created. #diff #changes #modified

docker diff $container_all

List port mappings

List port mappings or a specific mapping for the container. #port #netstat #bindings

docker port $container_running

Rename a container

Rename a container. #rename #mv

docker rename $container_all $new_name

Update container configuration

Update the resource limits of one or more containers dynamically without restarting them. #limits #cpu #memory #update

docker update $update_opts $container_running

Pause a container

Suspend all processes within a container. #pause #suspend #freeze

docker pause $container_running

Unpause a container

Resume all processes within a paused container. #unpause #resume #unfreeze

docker unpause $container_paused