🪟 Windows TippsModify Windows Support Phone Number with PowerShell(03.09.2026 um 00:00 Uhr)
🔧 AI Nachrichten Podcast: ChatGPT schwatzt Nutzern in Deutschland jetzt Werbung auf(28.08.2026 um 08:46 Uhr)
🪟 Windows TippsMicrosoft bringt Emoji 17.0 auf Windows 11(31.08.2026 um 08:16 Uhr)
🪟 Windows TippsModify Windows Support Phone Number with PowerShell(03.09.2026 um 00:00 Uhr)
🔧 AI Nachrichten Podcast: ChatGPT schwatzt Nutzern in Deutschland jetzt Werbung auf(28.08.2026 um 08:46 Uhr)
🪟 Windows TippsMicrosoft bringt Emoji 17.0 auf Windows 11(31.08.2026 um 08:16 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 3 Min Lesezeit
0

Differentiating Docker stop vs Kill

↗ Quelle (dev.to)
🗣️ Stimme:

Differentiating Docker stop vs Kill



This lab scenario provides a comprehensive overview of the differences between Docker's stop and kill commands, including their behavior, use cases, and practical examples. Understanding these differences is crucial for proper container management, especially when ensuring that applications shut down gracefully.



Introduction

In Docker, both stop and kill commands are used to terminate a running container, but they work differently:



docker stop: Sends a SIGTERM signal first, allowing the process to clean up before termination. If the process doesn't terminate within a specified timeout (default 10 seconds), Docker sends a SIGKILL signal to forcefully stop the process.



docker kill: Sends a SIGKILL signal immediately, terminating the process without allowing any clean-up.



Using docker stop

Step 1: Run a Container with a Process that Handles SIGTERM

Run a container with an Ubuntu image, simulating a process that handles the SIGTERM signal:



docker run --name graceful-termination -d ubuntu:latest /bin/bash -c "trap 'echo SIGTERM received; exit 0' SIGTERM; while :; do echo 'Running'; sleep 1; done"



Breakdown of the Command



docker run:



The primary Docker command to create and start a new container.



--name graceful-termination: Names the container graceful-termination for easier management and reference.



-d: Runs the container in detached mode, meaning it will run in the background.



ubuntu:latest:

Specifies the Docker image to use, in this case, the latest version of the Ubuntu image.



/bin/bash -c:



Starts a Bash shell within the container to execute the following script.

"trap 'echo SIGTERM received; exit 0' SIGTERM; while :; do echo 'Running'; sleep 1; done":



trap 'echo SIGTERM received; exit 0' SIGTERM: Sets up a trap to catch the SIGTERM signal. When this signal is received, the message "SIGTERM received" is printed and the script exits with a status of 0, indicating a graceful shutdown.

while :; do echo 'Running'; sleep 1; done: An infinite loop that prints "Running" every second. This keeps the container running until it is stopped.



Step 2: Stop the Container

Use the docker stop command to terminate the container:



docker stop graceful-termination



Step 3: Check the Container Logs

Examine the logs to verify how the process inside the container handled the SIGTERM signal:



docker logs graceful-termination



Expected Logs

Running

Running

Running

SIGTERM received



The logs should show that the process received the SIGTERM signal, executed the trap command, printed "SIGTERM received," and exited gracefully.



Using docker kill

Step 1: Run a Container with a Process that Would Handle SIGTERM

Run a similar container as before:



docker run --name force-termination -d ubuntu:latest /bin/bash -c "trap 'echo SIGTERM received; exit 0' SIGTERM; while :; do echo 'Running'; sleep 1; done"



Step 2: Kill the Container

Use the docker kill command to terminate the container:



docker kill force-termination



Step 3: Check the Container Logs

Examine the logs to verify the behavior of the process inside the container when terminated by SIGKILL:



docker logs force-termination



Expected Logs

Running

Running

Running



The logs should show continuous "Running" messages without any indication of "SIGTERM received," demonstrating that the process was abruptly terminated by the SIGKILL signal.



Summary of Differences

Signal Sent:



stop: Sends SIGTERM first, then SIGKILL if the process doesn't terminate within the timeout.

kill: Sends SIGKILL immediately.

Graceful Shutdown:



stop: Allows the process to handle the signal and perform clean-up operations.

**kill: **Does not allow any handling or clean-up.

Use Case:



stop: **Preferred for gracefully shutting down applications.

**kill:
Used for forcefully terminating unresponsive containers.

By examining the container logs, we can clearly see the difference in behavior. The stop command allows the application to handle the termination signal, whereas the kill command results in immediate termination without any clean-up.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Modify Windows Support Phone Number with PowerShell
1 Quelle
Die Zukunft des Einkaufens: Warum wir ein neues Kapitel aufschlagen (und wie du es mitschreiben kannst)
1 Quelle
ZDE Podcast 251: Wie sieht digitales Instore Marketing 2026 aus, Amit Chatterjee?
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Differentiating Docker stop vs Kill

Thematisch verwandte Begriffe: Differentiating, Docker, stop, Kill · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...