You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a Linux host reboots or the Docker service stops, systemd manages the shutdown sequence. Even if Docker is configured to let containers shut down gracefully, systemd will forcibly kill the entire Docker daemon if it takes longer than the systemd timeout limit.
Follow this guide to give systemd enough time to let Docker shut down your containers safely.
Prerequisites
Access to a Linux terminal.
sudo or root privileges on the host machine.
Step 1: Create a Systemd Service Override
Instead of editing the core Docker service file (which updates can overwrite), use systemd's built-in override mechanism.
Run the following command to open the override configuration file in your default text editor:
sudo systemctl edit docker.service
Step 2: Add the Timeout Configuration
A blank file will open (or a file with commented-out template text). Insert the following configuration block at the very top of the file:
[Service]TimeoutStopSec=30m
💡 Tip: Change 30m to whatever your longest-running container needs to safely stop. You can also use time units like 2m for two minutes or 90s for 90 seconds.
Save and close the text editor:
If using Nano: Press Ctrl + O then Enter to save, and Ctrl + X to exit.
If using Vim: Type :wq and press Enter.
Step 3: Reload Systemd and Apply Changes
Systemd needs to register the new configuration change. Run the daemon-reload command, then restart the Docker service to apply the new timeout window:
# Reload the systemd manager configuration
sudo systemctl daemon-reload
# Restart Docker to apply the changes
sudo systemctl restart docker
Step 4: Verify the New Configuration
To ensure systemd successfully accepted your new timeout setting, check the runtime attributes of the Docker service:
systemctl show docker.service | grep TimeoutStopSec
Expected Output:
TimeoutStopSecUSec=30min
(Note: Systemd often displays the verified time in microseconds or human-readable formats like 2min).
Troubleshooting & Verification
If your host reboots still result in hard-killed containers, you can verify how long Docker is taking to stop by inspecting the system journal after a restart:
journalctl -u docker.service -b -1
(This command shows the Docker service logs from the previous boot cycle to help identify which container is causing the delay).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When a Linux host reboots or the Docker service stops, systemd manages the shutdown sequence. Even if Docker is configured to let containers shut down gracefully, systemd will forcibly kill the entire Docker daemon if it takes longer than the systemd timeout limit.
Follow this guide to give systemd enough time to let Docker shut down your containers safely.
Prerequisites
Step 1: Create a Systemd Service Override
Instead of editing the core Docker service file (which updates can overwrite), use systemd's built-in override mechanism.
Run the following command to open the override configuration file in your default text editor:
Step 2: Add the Timeout Configuration
A blank file will open (or a file with commented-out template text). Insert the following configuration block at the very top of the file:
💡 Tip: Change 30m to whatever your longest-running container needs to safely stop. You can also use time units like 2m for two minutes or 90s for 90 seconds.
Save and close the text editor:
Step 3: Reload Systemd and Apply Changes
Systemd needs to register the new configuration change. Run the daemon-reload command, then restart the Docker service to apply the new timeout window:
Step 4: Verify the New Configuration
To ensure systemd successfully accepted your new timeout setting, check the runtime attributes of the Docker service:
Expected Output:
(Note: Systemd often displays the verified time in microseconds or human-readable formats like 2min).
Troubleshooting & Verification
If your host reboots still result in hard-killed containers, you can verify how long Docker is taking to stop by inspecting the system journal after a restart:
(This command shows the Docker service logs from the previous boot cycle to help identify which container is causing the delay).
Beta Was this translation helpful? Give feedback.
All reactions