Auto start docker-compose seafile on reboot

Hi all.

I installed Seafile following these instructions:

(realised I can’t put a link into this post) - I used the official Deploy Seafile with Docker from the seafile admin manual found on this site.

All working on Ubuntu 20.04.01. In fact, I’m delighted with it.

I am using a reverse proxy also in another docker.

I have a simple question - how do I get the seafile docker (based on the instructions above that I followed) which uses docker-compose to get my docker up and running to automatically start upon reboot?

The proxy one auto starts so I just need a solution to the seafile docker based on how I have installed it with those instructions. Thanks in advance for anyone who can tell me the solution!

I figured it out. So for those who come across this issue in the future, here is how to do it.

  1. Make sure your seafile docker is not running when you do this. Close it down first.

  2. Do NOT use the restart=always inside the docker-compose.yml - it will not work.

  3. Instead, as I am using Ubuntu, I created a .service for systemctl. So I literally typed this:

sudo nano /etc/systemd/system/docker-compose-seafile.service

copy and paste (but edit it to suit your directory) the below:

[Unit]
Description=Docker Compose Application Service
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/home/user/sea-file #this is the directory where your docker-compose.yml file is
ExecStart=/usr/bin/docker-compose up -d
ExecStop=/usr/bin/docker-compose down
TimeoutStartSec=0

[Install]
WantedBy=multi-user.target
#END

  • don’t copy the # comments - I just put the note about the directory in there for your benefit and also made it clear when the last line is in the file - you don’t need #END.

Then type this: sudo systemctl daemon-reload

then: sudo systemctl start docker-compose-seafile.service

That will start your docker.

Lastly, to ensure it starts on reboot, type: sudo systemctl enable docker-compose-seafile.service

Enjoy!

2 Likes

instead up -d and down, which will destroy and rebuild the whole stack on every reboot, I would make use
of stop & start commands to avoid any unwanted auto upgrades…

Actually, use it. Don’t know what happened for the op but this is the simplest and “docker” way. always or unless-stopped policies both restart container after a reboot.