diff --git a/Dockerfile b/Dockerfile index 3286fd60..b8ac1b5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,7 @@ RUN apk --no-cache add crane RUN crane pull "${CORROSION_IMAGE}" /corrosion.tar +# Uncloud-in-Docker (ucind) image for running Uncloud test clusters using Docker. FROM docker:27.3.1-dind AS ucind # Create system group and user 'uncloud'. RUN addgroup -S uncloud && adduser -SHD -h /nonexistent -G uncloud -g "" uncloud diff --git a/scripts/docker/entrypoint.sh b/scripts/docker/entrypoint.sh index d70f7044..074d9c2d 100755 --- a/scripts/docker/entrypoint.sh +++ b/scripts/docker/entrypoint.sh @@ -1,7 +1,28 @@ #!/bin/sh set -eu -# TODO: cleanup /run/docker.pid on exit to support container restart. +# Cleanup function to properly terminate background processes. +cleanup() { + echo "Terminating container processes..." + + # Terminate the main process if it has been started. + if [ -n "$MAIN_PID" ]; then + kill "$MAIN_PID" 2>/dev/null || true + fi + + # Terminate Docker daemon if PID file exists. + if [ -f /run/docker.pid ]; then + kill "$(cat /run/docker.pid)" 2>/dev/null || true + fi + + # Terminate socat proxy if running. + pkill socat 2>/dev/null || true + + # Wait for processes to terminate. + wait +} +trap cleanup INT TERM + dind dockerd & echo "Waiting for Docker in Docker to be ready..." timeout 5s sh -c "until docker info &> /dev/null; do sleep 0.1; done" @@ -14,4 +35,7 @@ docker load < /images/corrosion.tar echo "Proxying Uncloud API port 51000/tcp to Unix socket /run/uncloud/uncloud.sock..." socat TCP-LISTEN:51000,reuseaddr,fork,bind="$(hostname -i)" UNIX-CONNECT:/run/uncloud/uncloud.sock & -exec "$@" +# Execute the passed command and wait for it while maintaining signal handling. +"$@" & +MAIN_PID=$! +wait $MAIN_PID