Here are the steps I made to set a service into my Fedora server to start/stop my Docker-compose (Wikijs)

Why I decided to use a docker-compose into a Linux VM machine? —> for make it more stable, faster,portable, isolated, etc.

First I stared using Docker for Windows and it was a little bit unstable and not quite easy to handled, so when I switched to Docker compose into a Fedora VM and in that point it was a huge different(I do not recommend to use Docker in Windows); I use a Vmware hypervisor ( in the office we use it ).

NOTE:

The docker-compose.yml file is into a folder /opt/wikijs

Instructions:

  1. first go to /etc/systemd/system
  2. create the file ( eg: #touch wikijs.service )
  3. copy and paste the config below (eg: #nano wikijs.service):
# /etc/systemd/system

#########################
#    WIKIJS             #
#    SERVICE            #
##########################

[Unit]
Description=Docker Compose WIKIJS Service
Requires=docker.service
After=docker.service network.target

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/opt/wikijs
ExecStart=/usr/local/bin/docker-compose up -d
ExecStop=/usr/local/bin/docker-compose down
TimeoutStartSec=0

[Install]
WantedBy=multi-user.target
  1. test the service:
  • $systemctl start wikijs.service
  • $systemctl status wikijs.service
  • $systemctl enable wikijs.service

NOTE:

In my case I got an unexpected behavior with the wiki container(node.js client) so I added the restart: on-failure into my docker-compose.yml file and issue resolved.

....
  wiki:
    image: requarks/wiki:beta
    restart: on-failure     # added
....

For further information: