Docker uses the kernel of the host system and the host operating system, applications and their dependencies run in a container isolated from the rest. The container image contains the application to be run plus all necessary libraries.
Single docker applications are run with: docker run <application> it checks locally if it finds a container with the application, if not it tries to download it from the Internet https://hub.docker.com.
docker ps -a what is locally available
docker ps shows what docker is running.
For gentoo https://wiki.gentoo.org/wiki/Docker emerge app-containers/docker and docker-cli for the docker command line command.
for gentoo read the elogs to see if kernel options are missing, or cat /var/log/portage/elog/app-containers\:docker-28.0.4\:20251010-123137.log | grep CONFIG or
run /usr/share/docker/contrib/check-config.sh to see if the kernel contains everything docker requires
for systemd systemctl enable docker.service or for OpenRC rc-update add docker default
usermod -aG docker <username>
docker run hello-world
docker inspect hello-world
docker rm -f <container> delete a container
docker logs -f <container> check the logs
docker --help
The docker applications are stored once under /var/lib/docker.
The -v option behaves as a link between system and the docker container.
As example -v /opt/docker/homeassistant:/config creates a link between the systems /opt/docker/homeassistant directory and the dockers config
Often it is necessary to start multiple docker containers together. docker compose does this.
A project directory has to be created and a the file docker-compose.yml needs to be added. A good example is more advanced Home Assistant configuration that requires go2rtc stream server, mosquitto MQTT broker and esphome:
services:
homeassistant:
container_name: homeassistant
image: "ghcr.io/home-assistant/home-assistant:stable"
volumes:
- ./ha-config:/config
- /etc/localtime:/etc/localtime:ro
restart: unless-stopped
network_mode: host
depends_on:
mosquitto:
condition: service_healthy
go2rtc:
container_name: go2rtc
image: alexxit/go2rtc
volumes:
- ./go2rtc-config:/config
restart: unless-stopped
network_mode: host
mosquitto:
container_name: mosquitto
image: eclipse-mosquitto
ports:
- "1883:1883"
volumes:
- ./mosquitto-config/config:/mosquitto/config
- ./mosquitto-config/data:/mosquitto/data
- ./mosquitto-config/log:/mosquitto/log
restart: unless-stopped
# don't use network_mode: host
esphome:
container_name: esphome
image: ghcr.io/esphome/esphome:latest
volumes:
- ./esphome-config:/config
- /etc/localtime:/etc/localtime:ro
environment:
- TZ=Europe/Zurich
restart: unless-stopped
network_mode: host
The characters ./ in docker-compose.yml mean the directory where docker-compose.yml is.
With depends_on the sequence for starting the docker containers can be set. It is worth to add condition: service_healthy so it not just depends on the docker container being ready but also the application running.
Before starting the first time some containers required a configuration. As mosquitto ./mosquitto-config/config/mosquitto.conf
listener 1883 allow_anonymous true
A quick test if mosquitto works: In one console docker exec -it mosquitto mosquitto_sub -t test and then in an other docker exec -it mosquitto mosquitto_pub -t test -m hello or from an other computer mosquitto_sub -h 192.168.1.100 -p 1883 -t test
In side this directory it is then called as docker compose up -d also this pulls (downloads) all from https://hub.docker.com if not locally found. It also creates the directories containing persistent date defined by volumes:
The docker systemd service is aware of the running docker containers and since restart: unless-stopped is used no additional systemd service is required
run docker compose down && docker compose up -d when the file got modified