Docker Cheat Sheet

November 29, 2022

Containers

List running containers

docker ps

List all containers

docker ps -a

Start a container

docker start NAME

Stop a container

docker stop NAME

Kill a container

docker kill NAME

Debug a running container (starts /bin/sh inside the running container)

docker exec -it CONTAINER_ID /bin/sh

Images

Show all images

docker image ls -a

Delete image

docker image rm NAME

Run

Run container with following settings:

  • In detached mode
  • Name "dy"
  • Port 8002 externally mapped to port 8000 inside container
  • Using amazon/dynamodb-local image
docker run -d --name dy -p 8002:8000 amazon/dynamodb-local

Run a docker container interactivley

docker run -it ubuntu

Dockerfile

Dockerfiles can be used to build images.

To create an image from the dockerfile in our current directory.

docker build -t NAME_OF_IMAGE .