This document is a WORK IN PROGRESS.
This is just a quick personal cheat sheet: treat its contents with caution!
Docker¶
Docker is a utility to pack, ship and run any application as a lightweight container.
Reference(s)
- https://docs.docker.com/get-started/overview/
- https://docs.docker.com/
- https://www.docker.com/
- https://hub.docker.com/
- https://wiki.gentoo.org/wiki/Docker
- https://wiki.archlinux.org/index.php/Docker
- https://stackoverflow.com/questions/39223249/multiple-run-vs-single-chained-run-in-dockerfile-which-is-better
Table of contents¶
Install¶
Containers that produce kernel panics will induce kernel panics into the host operating system.
A correct kernel config is needed: See: https://wiki.gentoo.org/wiki/Docker#Kernel
Warning
After configuring the kernel don't forget to do a kernel make and rebuild!
Then, add it to your init system and start it:
Depending on your runit
implementation, either run:
Finally, check with # docker info
that everything is fine.
Config¶
-
TODO : proxy...
-
Allow docker to be run without
⚠️ Be careful with the associated security risks: https://docs.docker.com/engine/security/#docker-daemon-attack-surface⚠️sudo
(see https://askubuntu.com/a/477554): -
Active experimental features of docker, by creating the file
/etc/docker/daemon.json
with the following content: -
Change Docker root directory
/var/lib/docker
to another location (e.g./new/path/docker
):
TODO
Most distros using Runit won't store active services in the same directory. So let's
define a $ACTIVE_RUNIT_SERVICE_DIR
environment variable holding the path to that
directory. Most common paths are:
/service/
/var/service/
(e.g. for Void Linux)/etc/service/
/run/runit/service/
(e.g. for Artix Linux)
TODO
$ sudo systemctl stop docker.service
$ sudo systemctl stop docker.socket
$ sudo vi /lib/systemd/system/docker.service
> ...
~ > ExecStart=/usr/bin/dockerd --data-root="/new/path/docker" -H fd://
> ...
$ sudo mkdir -p /new/path/docker
$ sudo rsync -aqxP /var/lib/docker/ /new/path/docker
$ sudo systemctl daemon-reload
$ sudo systemctl start dockerd
$ ps aux | grep dockerd | grep -v grep
- It is possible to use a Btrfs or ZFS (or etc) storage driver for Docker, see https://wiki.archlinux.org/title/Docker#Storage_driver and https://wiki.gentoo.org/wiki/Docker#Storage_driver.
Use¶
-
Start a container with an interactive Bash shell:
- E.g.
-
Start a container with an interactive Bash shell, with a pseudo-tty and auto-remove the container when done executing:
--interactive
says you want an interactive session.--tty
allocates a pseudo-tty.--rm
tells Docker to go ahead and remove the container when it’s done executing.
-
"shell" into a running container (
docker-1.3+
): -
Inspect a running container:
-
Get the process ID for a container:
-
List the current mounted volumes for a container (and pretty print):
-
Copy files/folders between a container and your host:
-
List currently running containers:
-
List all containers:
-
Pull down an image (e.g. the latest Rocky Linux image):
-
List all images:
-
Remove a docker container:
-
Remove a docker image (⚠️ check if a container is associated to it beforehand with
$ docker ps -a
): -
Display system-wide information:
-
Remove unused data:
-
Show docker disk usage:
-
Remove all stopped containers, dangling images, and unused networks:
If you want to remove all unused images not just the dangling ones, add the-a
(--all
) option to the command.
Buildx¶
https://docs.docker.com/desktop/multi-arch/
Troubleshooting¶
error pair interfaces: operation not supported
¶
If you get an error like this one:
docker: Error response from daemon: failed to create endpoint cranky_einstein on network bridge: failed to add the host (vethf55744a) <=> sandbox (vethfce3f4d) pair interfaces: operation not supported.
Maybe you just did a Linux Kernel update, in that case: just restart the computer
warning /lib/rc/sh/openrc-run.sh: 258: ulimit: too many arguments
¶
Using OpenRC, with /bin/sh
as a symlink to /bin/dash
, a warning is issued every time Docker is
started or stopped:
/lib/rc/sh/openrc-run.sh: 258: ulimit: too many arguments
* docker: unable to apply RC_ULIMIT settings
* Stopping docker ...
See https://github.com/moby/moby/issues/43370.
If this cheat sheet has been useful to you, then please consider leaving a star here.