website/content/blog/composesystemd.md

48 lines
980 B
Markdown
Raw Normal View History

2020-01-15 21:51:49 -05:00
---
title: "Ensuring Docker Compose Startup with Systemd"
date: 2019-12-16T20:57:36-05:00
draft: false
2022-01-02 14:24:29 -05:00
tags: [ "Linux", "Containers" ]
2023-01-05 14:04:45 -05:00
medium_enabled: true
2020-01-15 21:51:49 -05:00
---
I've been having trouble getting some docker containers such as `nginx` to start automatically on bootup, even with the `restart: always` flag.
To compensate, I wrote a small systemd script and enabled it on startup.
`/etc/systemd/system/docker-compose.service`
```ini
[Unit]
Description=Docker Compose Application Service
Requires=network.target docker.service
After=network.target docker.service
2020-01-15 21:51:49 -05:00
[Service]
Type=oneshot
User=brandonrozek
Group=brandonrozek
RemainAfterExit=yes
WorkingDirectory=/home/brandonrozek/docker/
ExecStart=/usr/bin/docker-compose up -d --force-recreate
2020-01-15 21:51:49 -05:00
ExecStop=/usr/bin/docker-compose down
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target
```
To enable on startup
```bash
sudo systemctl enable docker-compose
```
To start now
```bash
sudo systemctl start docker-compose
```