Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to exit the docker container

Shulou Source: shulou.com Published: 2022-06-01 13:25:12 09月17日 Update

This article will explain in detail how to exit the docker container for everyone. Xiaobian thinks it is quite practical, so share it with you for reference. I hope you can gain something after reading this article.

Container signal usage

The programs we run in containers usually want to clean up before the container exits. A common way to do this is to listen for a signal and delay closing the container.

Docker provides this functionality:

╰─➤ docker stop --helpUsage: docker stop [OPTIONS] CONTAINER [CONTAINER...] Stop one or more running containersOptions: --help Print usage -t, --time int Seconds to wait for stop before killing it (default 10)

docker Version 1.13 and above can specify STOP_TIMEOUT and STOP_SIGNAL parameters directly when creating containers:

$ docker run --help...-- stop-signal string Signal to stop a container, SIGTERM by default (default "SIGTERM")--stop-timeout int Timeout (in seconds) to stop a container...

But...

Let's test one:

package mainimport ( "fmt" "os" "os/signal" "syscall" "time")func main() { fmt.Println("signal test") go func() { for { c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGTERM) s :=

Tags: Containers signals processes articles methods more monitoring running good practical content methods functions reasons parameters commonly used articles versions knowledge programs Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB OPPO Reno Docker Xiaomi Redmi