❯ cat ~/.config/systemd/user/docker-compose.service
[Unit]
Description=Docker Compose
After=network.target
# After=docker.service
[Service]
WorkingDirectory=%h
ExecStart=/usr/bin/docker-compose up -d --remove-orphans
#ExecReload=/usr/bin/docker-compose up -d --remove-orphans
ExecStop=/usr/bin/docker-compose down
#Type=oneshot
#Restart=always
[Install]
WantedBy=default.target
~
❯ cat ~/.config/systemd/user/docker-compose.timer
[Timer]
OnStartupSec=1
# Every 15 minutes
OnCalendar=*:0/15
Persistent=True
[Install]
WantedBy=timers.target
❯ systemctl start --user docker-compose.timer
❯ systemctl status --user docker-compose
Found existing alias for "systemctl status". You should use: "sc-status"
● docker-compose.service - Docker Compose
Loaded: loaded (/home/sergey/.config/systemd/user/docker-compose.service; disabled; vendor preset: enabled)
Active: inactive (dead) since Fri 2021-02-19 08:24:09 MSK; 6min ago
TriggeredBy: ● docker-compose.timer
Process: 26348 ExecStart=/usr/bin/docker-compose up -d --remove-orphans (code=exited, status=0/SUCCESS)
Process: 26709 ExecStop=/usr/bin/docker-compose down (code=exited, status=0/SUCCESS)
Main PID: 26348 (code=exited, status=0/SUCCESS)
Feb 19 08:24:08 sergey-pc docker-compose[26709]: Stopping sergey_redis_1 ...
Feb 19 08:24:08 sergey-pc docker-compose[26709]: Stopping sergey_postgres_1 ... done
Feb 19 08:24:08 sergey-pc docker-compose[26709]: Stopping sergey_redis_1 ... done
Feb 19 08:24:08 sergey-pc docker-compose[26709]: Removing sergey_postgres_1 ...
Feb 19 08:24:08 sergey-pc docker-compose[26709]: Removing sergey_redis_1 ...
Feb 19 08:24:08 sergey-pc docker-compose[26709]: Removing sergey_redis_1 ... done
Feb 19 08:24:09 sergey-pc docker-compose[26709]: Removing sergey_postgres_1 ... done
Feb 19 08:24:09 sergey-pc docker-compose[26709]: Removing network sergey_postgres
Feb 19 08:24:09 sergey-pc docker-compose[26709]: Removing network sergey_redis
Feb 19 08:24:09 sergey-pc systemd[1363]: docker-compose.service: Succeeded.
~
❯ docker-compose up -d --remove-orphans
Found existing alias for "docker-compose up -d". You should use: "dcupd"
Building with native build. Learn about native build in Compose here: https://docs.docker.com/go/compose-native-build/
Creating network "sergey_postgres" with driver "bridge"
Creating network "sergey_redis" with driver "bridge"
Creating sergey_redis_1 ... done
Creating sergey_postgres_1 ... done
~ took 2s
❯ psql -U postgres -h 'localhost'
Password for user postgres:
psql (13.2)
Type "help" for help.
postgres=# \q
~
❯ docker-compose down
Found existing alias for "docker-compose down". You should use: "dcdn"
Stopping sergey_postgres_1 ... done
Stopping sergey_redis_1 ... done
Removing sergey_postgres_1 ... done
Removing sergey_redis_1 ... done
Removing network sergey_postgres
Removing network sergey_redis
Мне непонятно:
- Почему
docker-compose.timer: Failed to queue unit startup job: Unit docker.service not found.
, ведь:
❯ systemctl status docker
Found existing alias for "systemctl status". You should use: "sc-status"
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2021-02-19 04:49:35 MSK; 3h 45min ago
...
- Почему юнит останавливает контейнеры и удаляет сети, т.е. выполняется
docker-compose down
?
Я ожидал что все будет работать. Такое поведение для меня загадка. Ест-но если через систему запускать, то все нормально…