Skip to content

Instantly share code, notes, and snippets.

@tomasnorre
Last active December 12, 2022 15:02
Show Gist options
  • Save tomasnorre/c85094c0f1e8acba85b138bf863115d5 to your computer and use it in GitHub Desktop.
Save tomasnorre/c85094c0f1e8acba85b138bf863115d5 to your computer and use it in GitHub Desktop.
Problems with systemctl in docker

Problem

My services doesn't restart, what could this be caused?

Steps to reproduce

  1. docker build -t systemctl:latest .
  2. docker run -ti systemctl:latest bash
  3. systemctl status sleep <-- Dead inactive
  4. systemctl restart sleep <-- Runs for 5 secs before it exists
  5. systemctl status sleep <-- Dead inactive, and doesn't start up again.
FROM ubuntu:22.04
RUN apt update && apt install -y systemctl
COPY sleep.service /etc/systemd/system/sleep.service
RUN systemctl enable sleep
CMD ["bash"]
[Unit]
Description=Sleep Service
[Service]
Restart=always
RestartSec=3
ExecStart=/bin/sleep 5
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment