Tuesday, September 8, 2020

Run Docker Container as a Service

 Ref: https://www.jetbrains.com/help/youtrack/standalone/run-docker-container-as-service.html


Docker team recommends to use cross-platform built-in restart policy for running container as a service. For this, configure your docker service to start on system boot and simply add parameter --restart unless-stopped to the docker run command that starts YouTrack.


However, when it comes to the sequential start of several services (including YouTrack), the restart policy method will not suit. You can use a process manager instead.


Here's an example of how to run YouTrack container as a service on Linux with help of systemd.


To run YouTrack container as a service on Linux with systemd:

Create a service descriptor file /etc/systemd/system/docker.youtrack.service:

[Unit]
Description=YouTrack Service
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/docker exec %n stop
ExecStartPre=-/usr/bin/docker rm %n
ExecStartPre=/usr/bin/docker pull jetbrains/youtrack:<version>
ExecStart=/usr/bin/docker run --rm --name %n \
    -v <path to data directory>:/opt/youtrack/data \
    -v <path to conf directory>:/opt/youtrack/conf \
    -v <path to logs directory>:/opt/youtrack/logs \
    -v <path to backups directory>:/opt/youtrack/backups \
    -p <port on host>:8080 \
    jetbrains/youtrack:<version>
[Install]
WantedBy=default.target


Enable starting the service on system boot with the following command:


systemctl enable docker.youtrack


You can also stop and start the service manually at any moment with the following commands, respectively:


sudo service docker.youtrack stop

sudo service docker.youtrack start


No comments:

Post a Comment

Install and use xorg-server on macOS via Homebrew

  The instructions to install and use xorg-server on macOS via Homebrew: Install Homebrew (if you haven't already): /bin/bash -c ...