Skip to content

Basics

Container Status

Status Description
created A container that has never been started.
running A running container, started by either docker start or docker run.
paused A paused container. See docker pause.
restarting A container which is starting due to the designated restart policy for that container.
exited A container which is no longer running. For example, the process inside the container completed or the container was stopped using the docker stop command.
removing A container which is in the process of being removed. See docker rm.
dead A "defunct" container; for example, a container that was only partially removed because resources were kept busy by an external process. dead containers cannot be (re)started, only removed.

Refer to container lifecycle for details.

https://docs.docker.com/reference/cli/docker/container/ls/#status

Common Tasks

Download an image

docker pull ubuntu:22.04

https://docs.docker.com/reference/cli/docker/image/pull/

Create and run a new container

docker run --name demo1 -it ubuntu:22.04 /bin/bash

Common Options

Option Description
--name Assign a name to the container
-i Keep STDIN open even if not attached
-t Allocate a pseudo-TTY
-d Run container in background and print container ID
-v Bind mount a volume
-p Publish a container's port(s) to the host
--rm Automatically remove the container and its associated anonymous volumes when it exits

https://docs.docker.com/reference/cli/docker/container/run/

Check container logs

docker logs -f demo1

Common Options

Option Description
-f Follow log output

https://docs.docker.com/reference/cli/docker/container/logs/

Continue with an exited container

docker start -ai demo1

Common Options

Option Description
-a Attach STDOUT/STDERR and forward signals
-i Attach container's STDIN

https://docs.docker.com/reference/cli/docker/container/start/

Remove all stopped containers

docker container prune

https://docs.docker.com/reference/cli/docker/container/prune/

List images

docker images

https://docs.docker.com/reference/cli/docker/image/ls/

Remove an image

docker rmi ubuntu

https://docs.docker.com/reference/cli/docker/image/rm/

Remove unused images

docker image prune

Common Options

Option Description
-a Remove all unused images, not just dangling ones

https://docs.docker.com/reference/cli/docker/image/prune/