Creating Systemd Services for Docker Compose
This guide will walk you through creating systemd services to manage your Docker Compose deployments. This ensures that your services start automatically on boot and can be managed easily using standard systemd commands.
Table of Contents
- Prerequisites
- Creating the Systemd Service for SVM
- Creating the Systemd Service for Liberty
- Enabling and Starting the Services
- Additional Resources
Prerequisites
Before you begin, ensure the following prerequisites are met:
- You have Docker and Docker Compose installed on your server.
- You have completed the deployment steps for Liberty Framework using Docker Compose.
Creating the Systemd Service for Admin Tools
Create a service file for
docker-admin
:sudo nano /etc/systemd/system/docker-admin.service
Paste the following content into the file:
[Unit] Description=Liberty Admin Tools Service PartOf=docker.service After=docker.service [Service] Type=simple RemainAfterExit=true WorkingDirectory=/app/liberty-admin/ ExecStart=/usr/local/bin/docker-compose -f /app/liberty-admin/docker-compose.yml start ExecStop=/usr/local/bin/docker-compose -f /app/liberty-admin/docker-compose.yml stop [Install] WantedBy=multi-user.target
Save and close the file.
Creating the Systemd Service for Liberty Framework
- Open a terminal.
- Create a new directory:
mkdir -p /app/liberty-framework cd /app/liberty-framework
- Download the Docker Compose file from the provided URL, Using
curl
:curl -L -o docker-compose.yml https://github.com/fblettner/liberty-public/blob/main/release/latest/liberty-framework.yml
Create a service file for
docker-liberty
:sudo nano /etc/systemd/system/docker-liberty.service
Paste the following content into the file:
[Unit] Description=Liberty Framework Service PartOf=docker.service After=docker.service [Service] Type=simple RemainAfterExit=true WorkingDirectory=/app/liberty/ ExecStart=/usr/local/bin/docker-compose -f /app/liberty-framework/docker-compose.yml start ExecStop=/usr/local/bin/docker-compose -f /app/liberty-framework/liberty-compose.yaml stop [Install] WantedBy=multi-user.target
- Save and close the file.
Enabling and Starting the Services
Enable the created services to start on boot:
sudo systemctl enable docker-liberty.service sudo systemctl enable docker-admin.service
Start the services immediately:
sudo systemctl start docker-liberty.service sudo systemctl start docker-admin.service
Check the status of the services to ensure they are running:
sudo systemctl status docker-liberty.service sudo systemctl status docker-admin.service
Additional Resources
By following this guide, you should be able to create and manage systemd services for your Docker Compose deployments seamlessly. If you run into any issues or have any questions, refer to the additional resources provided or reach out to the respective support communities.