From 02707d75cedcf7d603b693c92655b6af55e8e3fa Mon Sep 17 00:00:00 2001 From: Bo Lopker Date: Tue, 18 Sep 2018 03:57:51 -0700 Subject: [PATCH 1/2] Stop container gracefully --- docker-compose.yml | 7 +++++++ entrypoint.sh | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0115f80 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +version: '3' + +services: + dockerhost: + build: + context: . + cap_add: [ 'NET_ADMIN', 'NET_RAW' ] diff --git a/entrypoint.sh b/entrypoint.sh index 273487c..45dbcfa 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,9 @@ #!/bin/sh set -e +# Stop gracefully +trap : TERM INT + DOCKER_HOST="$(getent hosts host.docker.internal | cut -d' ' -f1)" if [ ! $DOCKER_HOST ]; then DOCKER_HOST=$(ip route | grep '^default' | cut -d' ' -f3) @@ -14,4 +17,4 @@ iptables -t nat -I PREROUTING -p tcp --match multiport --dports "$FORWARDING_POR iptables -t nat -I POSTROUTING -j MASQUERADE # run forever -tail -f /dev/null +tail -f /dev/null & wait From 7d0ebc23e61b4a18e67f8a69cc309e25e8a404b4 Mon Sep 17 00:00:00 2001 From: Bengt Brodersen Date: Wed, 19 Sep 2018 10:27:19 +0200 Subject: [PATCH 2/2] use sleep instead of tail to keep container alive --- entrypoint.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 45dbcfa..22434f7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,9 +1,6 @@ #!/bin/sh set -e -# Stop gracefully -trap : TERM INT - DOCKER_HOST="$(getent hosts host.docker.internal | cut -d' ' -f1)" if [ ! $DOCKER_HOST ]; then DOCKER_HOST=$(ip route | grep '^default' | cut -d' ' -f3) @@ -17,4 +14,4 @@ iptables -t nat -I PREROUTING -p tcp --match multiport --dports "$FORWARDING_POR iptables -t nat -I POSTROUTING -j MASQUERADE # run forever -tail -f /dev/null & wait +trap "exit 0;" TERM INT; while true; do sleep 1d; done & wait