2

I have a very specific issue with running a Docker container on boot using systemd.

The container starts and stops successfully with the following scripts:

start-container.sh

#!/usr/bin/env bash
sleep 5
docker start container_name

stop-container.sh

#!/usr/bin/env bash
sleep 5
docker stop container_name

However, when I configure the following service using systemd, it does not run successfully:

[Unit]
Description=Docker Container
After=network.target
After=systemd-user-sessions.service
After=network-online.target
After=multi-user.target

[Service]
User=root
Type=simple
ExecStart=/home/seed/scripts/start-container.sh
ExecStop=/home/seed/scripts/stop-container.sh
TimeoutSec=60
Restart=on-failure
RestartSec=30
StartLimitInterval=350
StartLimitBurst=10

[Install]
WantedBy=default.target
1

1 Answer 1

0

Absolute paths are key to success in shell scripting.

Why not make it without home directory scripts (that is not good practise in services) :

[Unit]
Description=Docker Container
After=network.target
After=systemd-user-sessions.service
After=network-online.target
After=multi-user.target

[Service]
User=root
Type=simple
ExecStart=/usr/bin/docker start -a container_name
ExecStop=/usr/bin/docker stop -t 5 container_name
TimeoutSec=60
Restart=on-failure
RestartSec=30
StartLimitInterval=350
StartLimitBurst=10

[Install]
WantedBy=default.target

Happy dockering!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.