Run Docker Container as a Service
Docker recommends using their cross-platform built-in restart policy for running a container as a service. For this, configure your Docker service to start on system boot and add the
--restart unless-stopped parameter to the
docker run command that starts Hub.
If you want to start multiple services one after the other, including Hub, the restart policy won't work well. In such cases, it's better to use a process manager instead.
Specific instructions for setting up a restart policy vary by operating system. To make sure you see information that is relevant to your installation, select the tab that corresponds with the operating system used in your host environment.
Here's an example of how to run Hub container as a service on Linux with help of
To run Hub container as a service on Linux with systemd
Create a service descriptor file
/etc/systemd/system/docker.hub.service:[Unit] Description=Hub 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/hub:<version> ExecStart=/usr/bin/docker run --rm --name %n \ -v <path to data directory>:/opt/hub/data \ -v <path to conf directory>:/opt/hub/conf \ -v <path to logs directory>:/opt/hub/logs \ -v <path to backups directory>:/opt/hub/backups \ -p <port on host>:8080 \ --stop-timeout 60 \ jetbrains/hub:<version> ExecStop=/usr/bin/docker exec %n stop [Install] WantedBy=default.target
Enable starting the service on system boot with the following command:systemctl enable docker.hub
You can also stop and start the service manually at any moment with the following commands, respectively:
For Windows, you can run Hub as a service with the help of Docker Compose.
Ensure you have Docker Desktop installed on your Windows system. For instructions, please refer to the Docker documentation.
Create a Docker Compose File.
A Docker Compose file is typically a
.ymlthat defines your containerized application and its configuration. In this case, your file contains the parameters you would typically use to run Hub.
Here's an example you can use as a guide for writing your file:version: "3" services: Hub: container_name: hub-server image: jetbrains/hub:<version> user: "13001:13001" restart: unless-stopped ports: - "<port on host>:8080" volumes: - <path to data folder>:/opt/hub/data - <path to conf folder>:/opt/hub/conf - <path to logs folder>:/opt/hub/logs - <path to backups folder>:/opt/hub/backups
Run Docker Compose as a Windows Service.
Open a Command Prompt or PowerShell with administrative privileges. Navigate to the directory where your Docker Compose file is located and use the following command to run it as a Windows service:docker-compose -f docker-compose.yml up -d
This command starts Hub as a Windows service in detached mode, running it in the background.
You can then manage your Hub service using standard Docker commands. For example:
To stop the service, use:
docker-compose -f docker-compose.yml down
To check the service status, use:
docker-compose -f docker-compose.yml ps
If the server shuts down for whatever reason, Docker will automatically restart the container on reboot.
In order for this to work, you must configure the Docker service to start automatically when the server boots up. For specific instructions, please refer to the documentation for your server operating system.
You will also need to ensure that the Windows user account that runs the service is automatically logged in on reboot. This is typically done at the Windows service level and is managed separately from the Docker container's user context. For specific instructions, please refer to the documentation for the application that manages user access in your server environment.