Skip to content

Instantly share code, notes, and snippets.

Last active Aug 19, 2019
What would you like to do?
Basic Docker Commands

Notes from Docker Deep Dive, Nigel Poulton & dockercom & my stuff

Working with Images

Basic commands

docker version
docker info
rpm -qif /usr/bin/docker

Looking for Storage Driver & Docker Root Dir

docker system info

Docker Image

docker image pull
docker image push
docker image inspect
dokcer image rm

docker image pull img_name [-a]
docker image ls
docker image ls --digests

Enter underlaying Linux VM:

screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty

ls -l [DockerRootDir]/[StorageDriver]/{diff}
ls -l /var/lib/docker/overlay2/{layer_num/dir_?}/{diff}

Size <> 0B are layers & others added to create .config file

docker history img_name

Image config file = image manifest file

docker image inspect img_name

Delete image

docker image rm img_name


DTR - Docker Trusted Registry

registry / repo / image (tag) {repo} / latest //defaults; Docker Hub

docker image pull

content hashes -> compression -> distribution hashes

Containerizing an App


In root add Dockerfile File edited from

# base image
FROM python:2.7-slim

LABEL maintainer="name@domain.cos"

# Set the working directory to /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host -r requirements.txt

# Make port 80 available to the world outside this container

# Define environment variable

# Run when the container launches
CMD ["python", ""]

Containerizing an App

Build an image, tagged as name, current directory where code is a contex

docker image build -t name .

docker image build -t name

Multi-stage Builds


FROM .. AS build-stage-0
RUN ..

FROM .. AS build-stage-1
RUN ..
RUN ..

FROM .. AS production-stage
COPY --from=build-stage-0 /usr/scr/... .
COPY --from=build-stage-1 /usr/scr/... .
CMD [..]


docker image build -t multistage .

Working with Containers

Interactive terminal

docker container run -it alpine sh
ps -elf

<Ctr+P+Q> - exit container without teminating its main process (closing container)

docker container run -d alpine sleep 1d


In runnning container (should not do?)

docker exec -it risk_app /bin/sh                  // CLI
docker exec -it risk_app bundle exec rails c      // rails c
docker exec risk_app ls -l

Removing quitely all containers

docker container rm $(docker ps -aq) -f


engine / daemon

Mac / Linux / Windows

container / app


Secure Swarm

Security & Orchestration

docker swarm init
docker swarm join

docker swarm join-token [manager | worker]
docker node ls                             // if you want to seenot only mgrs but also workers, check on manager CLI
docker swarm join-token rotate [manager | worker]   // run o mgr
sudo openssl x509 in [..] -text            // see clients ceritifcates;
                                           // Subject: O organization, OU org unit, CN Cannonical Name 

Lock Swarm with Autolock

new Swarm:

docker swarm init --autolock

existing Swarm

docker swarm update --autolock=true

service docker restart
docker node ls  // does not work on locked
docker swarm unlock
{enter unlock key given when locking}

docker swarm update --cert-expiry 48h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment