markdown 添加doker-compose作为系统单元
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 添加doker-compose作为系统单元相关的知识,希望对你有一定的参考价值。
Docker compose as a systemd unit
================================
Create file `/etc/systemd/system/docker-compose@.service`
```ini
[Unit]
Description=%i service with docker compose
Requires=docker.service
After=docker.service
[Service]
Restart=always
WorkingDirectory=/etc/docker/compose/%i
# Remove old containers, images and volumes
ExecStartPre=/usr/local/bin/docker-compose down -v
ExecStartPre=/usr/local/bin/docker-compose rm -fv
ExecStartPre=-/bin/bash -c 'docker volume ls -qf "name=%i_" | xargs docker volume rm'
ExecStartPre=-/bin/bash -c 'docker network ls -qf "name=%i_" | xargs docker network rm'
ExecStartPre=-/bin/bash -c 'docker ps -aqf "name=%i_*" | xargs docker rm'
# Compose up
ExecStart=/usr/bin/docker-compose up
# Compose down, remove containers and volumes
ExecStop=/usr/bin/docker-compose down -v
[Install]
WantedBy=multi-user.target
```
Place your `docker-compose.yml` into `/etc/docker/compose/myservice` and call
```
systemctl start docker-compose@myservice
```
Docker cleanup timer with system
================================
Create `/etc/systemd/system/docker-cleanup.timer` with this content:
```ini
[Unit]
Description=Docker cleanup timer
[Timer]
OnUnitInactiveSec=12h
[Install]
WantedBy=timers.target
```
And service file `/etc/systemd/system/docker-cleanup.service`:
```ini
[Unit]
Description=Docker cleanup
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
WorkingDirectory=/tmp
User=root
Group=root
ExecStart=/usr/bin/docker system prune -f
[Install]
WantedBy=multi-user.target
```
run `systemctl enable docker-cleanup.timer` for enabling the timer
以上是关于markdown 添加doker-compose作为系统单元的主要内容,如果未能解决你的问题,请参考以下文章
markdown 在Javascript中删除Diacritics(可用作普通函数,`String`对象和jQuery插件的扩展)。
markdown 将图像添加到Gist.markdown中的markdown文件
timescaledb 集成prometheus
markdown 如何在Github Markdown文件上添加公式
markdown怎么添加内容目录
Markdown小技巧---添加空格