Docker Reference

Kip Landergren

(Updated: )

My cheat sheet for docker covering documentation links and common commands to build manage images and containers.

Contents#

Documentation#

Official Docker Compose Documentation

Official Docker Machine Documentation

Official Docker Reference

Commands#

Build from file Dockerfile.custom relative to the current working directory:

docker build --file Dockerfile.custom .

list containers

docker ps

list images

docker images

run a container named “test-nginx” from image “nginx” and automatically remove the container when it exits:

docker run --name test-nginx --rm nginx

Removing unused data:

docker system prune --help

Get a shell in a running container:

docker exec -it mycontainer bash

docker-compose Commands#

List containers:

docker-compose ps

List services:

docker-compose ps --services

Rebuild a specific service:

docker-compose up --detach --build SERVICE_NAME

Work with logs:

docker-compose logs --follow SERVICE_NAME
docker-compose logs --tail=50 SERVICE_NAME
docker-compose logs --tail=50 --follow SERVICE_NAME

Terminology#

container#
1.

A runnable instance of an image.

Related:

container, service, stack#
1.

How docker describes app building, from bottom of hierarchy to the top. a service is how containers behave in production. a stack defines all interactions of services.

Related:

Dockerfile#
1.

Text file containing all necessary instructions to assemble an image.

Related:

image#
1.

A read-only template with instructions for creating a compute environment.

Related:

Working with Docker and Kubernetes#

To set up Docker environment variables to use the Docker daemon in minikube, allowing easy access to built images:

eval $(minikube docker-env)

and to tear down:

eval $(minikube docker-env --unset)