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.
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 ps what is running
docker ps -a what is around
docker rm -f <container> delete a container
docker logs -f <container> check the logs
docker --help
When docker runs it checks locally if it finds a container if not it tries to download it from the Internet https://hub.docker.com. docker ps shows what docker is running.
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
With docker compose, multiple docker containers can be started together.
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
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.
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
The docker systemd service is aware of the running docker containers and since restart: unless-stopped is used no additional systemd service is required