Docker cheat sheet

Dockerfile

Install with apt-get and cleanup

RUN apt-get update \
 && DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y \
 && DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/* /var/log/* /var/cache/*

Setup locales with apt-get

RUN apt-get update \
 && DEBIAN_FRONTEND=noninteractive apt-get install -y locales \
 && sed -i -e 's/# de_DE.UTF-8 UTF-8/de_DE.UTF-8 UTF-8/' /etc/locale.gen \
 && dpkg-reconfigure --frontend=noninteractive locales \
 && update-locale LANG=de_DE.UTF-8

Install with apk and cleanup

RUN apk add --no-cache git \
 && rm -rf /var/cache/apk/*

Cleanup Docker

Prune some not using containers

#remove all containers not running for minimum 1 month or stick in created mode
docker container ls -a --filter status=exited --filter status=created --format '{{.ID}} {{.Status}}' | awk '/months ago/{print $1 }' | xargs --no-run-if-empty docker container rm
docker network prune -f
docker volume prune -f

Docker for Mac

Enter Moby Linux VM

Running a shell in the namespaces of pid 1 of the host:

docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh

Using screen to connect to the given tty

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