Last active
July 3, 2023 05:43
-
-
Save manhdaovan/b60ce1de6164cfea8e675064dbdc38e9 to your computer and use it in GitHub Desktop.
Testing graceful shutdown with PID != 1 in Docker container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM alpine:latest | |
| WORKDIR /app | |
| COPY . /app | |
| ENTRYPOINT [ "ash", "entry.sh" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cd /app | |
| ./test_gracefulMaMak |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "os" | |
| "os/signal" | |
| "syscall" | |
| ) | |
| func main() { | |
| fmt.Println("main started") | |
| shutdown := make(chan os.Signal, 2) | |
| signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM) | |
| select { | |
| case s := <-shutdown: | |
| fmt.Println("shutdown server by received signal:", s.String()) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| build-app: | |
| GOOS=linux go build -o test_graceful main.go && \ | |
| chmod +x test_graceful | |
| build-image: build-app | |
| docker build -t test_graceful . | |
| run-app-on-docker: | |
| docker run -it test_graceful |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
docker run ...command)docker stop containerIDps auxinside container (app run with PID = 7)