Skip to content

Instantly share code, notes, and snippets.

@craigphicks
Last active May 23, 2025 04:02
Show Gist options
  • Save craigphicks/321073d3e8dfadb8fa8db7c26dabe587 to your computer and use it in GitHub Desktop.
Save craigphicks/321073d3e8dfadb8fa8db7c26dabe587 to your computer and use it in GitHub Desktop.
systemd user service to run a docker container

The systemd servicefile codium-server.service is executed at boot time. It executes a script startup-codium-server.sh which calls docker run ...., the details of which are not shown here. The docker container being run will fork, and the service can/does not keep track of it. That's why Type=oneshot is used in the service file.

Lingering has to be set up so that the user service can be run even when the user has not logged on:

loginctl enable-linger $USER

To check that linger setting

loginctl show-user $USER -p Linger

Setup and start the service

systemctl --user daemon-reload
systemctl --user enable codium-server.service
systemctl --user start codium-server.service
[Unit]
Description=codium-server Service
After=default.target
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/home/gupper/github/codium-server
ExecStart=/home/gupper/github/codium-server/startup-codium-server.sh
ExecStop=docker stop codium-server
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment