mykb/docs/docker.md

35 lines
1.0 KiB
Markdown
Raw Normal View History

2023-07-04 12:32:25 +02:00
# Docker
General tips and tricks around docker, as it's usage has become unavoidable.
## Docker compose as systemd services
You will be able to start any docker compose program via `systemctl start docker-compose@<program>`.
Create the file `/etc/systemd/system/docker-compose@.service` with the following content:
2023-07-04 12:35:43 +02:00
```ini
2023-07-04 12:32:25 +02:00
[Unit]
Description=%i service with docker compose
PartOf=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=true
WorkingDirectory=/etc/docker/compose/%i
ExecStart=/usr/bin/docker compose up -d
ExecStop=/usr/bin/docker compose stop
[Install]
WantedBy=multi-user.target
```
2023-07-04 12:37:13 +02:00
Create directories as necessary and place your `docker-compose.yml` in an appropriately named folder (as an example: "myprogram") in `/etc/docker/compose`.
2023-07-04 12:32:25 +02:00
Ergo: Your docker-compose.yml should be in `/etc/docker/compose/myprogram/docker-compose.yml`.
Reload the daemon and start your service:
2023-07-04 12:35:43 +02:00
```sh
2023-07-04 12:32:25 +02:00
systemctl daemon-reload
sysetmctl start docker-compose@myprogram
```
More ideas:
https://gist.github.com/mosquito/b23e1c1e5723a7fd9e6568e5cf91180f