Skip to content

Docker cheatsheet

List containers

List currently running containers

docker ps

List all containers

docker ps -a

List images

docker images

Starting containers

Start a container with an interactive shell

  docker run -ti <image_name> /bin/bash

Start a container in the background

  docker run -d <image_name>

Start a container and redirect local port to container port

docker run -p 4000:80 <image_name>

Attach to running container

Run shell in the container

docker exec -ti <container_name> bash

Copying files to/from container

Copy files/folders between a container and your host

docker cp foo.txt <container_name>:/foo.txt

Inspecting containers

Inspect a running container

  docker inspect <container_name> (or <container_id>)

Get the process ID for a container

docker inspect --format {{.State.Pid}} <container_name_or_ID>

List the current mounted volumes for a container

docker inspect --format='{{json .Volumes}}' <container_id> | python -mjson.tool

Save/load image

Save docker image as tarball

docker save ubuntu -o /tmp/ubuntu.tgz

Load tarball as docker image

docker load < ubuntu.tgz


Dockerfile examples

Using intermediate container for build

FROM ubuntu as intermediate

COPY secret/key /tmp/
RUN scp -i /tmp/key build@acme/files .

FROM ubuntu
COPY --from=intermediate /app .

Configuring docker client

Configure docker CLI to use proxy server

export http_proxy=""
export https_proxy=""

Configure Docker client to use remote host

export DOCKER_HOST=tcp://
docker ps

Docker daemon

Start docker daemon

docker -d

Docker API

List images



with parameters



  • q - search term
  • n - number of results per page
  • page - page number



Check status