Skip to content

Commit 5e35fc4

Browse files
Kill dockerd immediately on container exit
When dockerd is running inside the container, skip exec so the entrypoint shell stays alive to run an EXIT trap that SIGKILL's dockerd. This avoids a ~60s wait for dockerd's graceful shutdown when the agent process exits.
1 parent 98bfc51 commit 5e35fc4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

assets/entrypoint.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ if [ "${ASYLUM_DOCKER:-}" = "1" ]; then
1010
elif command -v dockerd >/dev/null 2>&1; then
1111
echo "Starting Docker daemon..."
1212
sudo dockerd --storage-driver=vfs --log-level=warn >/tmp/dockerd.log 2>&1 &
13+
DOCKERD_PID=$!
1314
for i in $(seq 1 30); do
1415
if docker info >/dev/null 2>&1; then
1516
echo "Docker daemon ready"
@@ -140,4 +141,11 @@ if [ -t 0 ] && [ -t 1 ]; then
140141
echo ""
141142
fi
142143

143-
exec "$@"
144+
# If dockerd is running, skip exec so the trap can kill it on exit.
145+
# Otherwise, exec replaces this shell (saves a process).
146+
if [ -n "${DOCKERD_PID:-}" ]; then
147+
trap 'sudo kill -9 $DOCKERD_PID 2>/dev/null' EXIT
148+
"$@"
149+
else
150+
exec "$@"
151+
fi

0 commit comments

Comments
 (0)