From 96baa25f502ee1ddcff51aa8aa4e388d249393ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Tanhuanp=C3=A4=C3=A4?= Date: Sat, 3 Feb 2024 21:19:31 +0200 Subject: [PATCH] Add a wrapper for docker that waits for daemon See linked gitlab issue for more info: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27300 --- Dockerfile | 5 +++++ utils/docker-wrapper.sh | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 utils/docker-wrapper.sh diff --git a/Dockerfile b/Dockerfile index 3449817..f94c51d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -73,6 +73,11 @@ ENV DOCKER_CLI_EXPERIMENTAL=enabled WORKDIR /app +# Add a wrapper for docker that waits for docker daemon. See: +# https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27300 +COPY ./utils/docker-wrapper.sh /usr/local/bin/docker +RUN chmod a+x /usr/local/bin/docker + RUN apk add --no-cache \ apache2-utils \ bash \ diff --git a/utils/docker-wrapper.sh b/utils/docker-wrapper.sh new file mode 100644 index 0000000..c3e7ee1 --- /dev/null +++ b/utils/docker-wrapper.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# A wrapper for docker to check that wait for docker daemon to spin up. See: +# https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27300 + +wait_for_dockerd() { + END=$(expr $(date +%s) + 30) # Wait for 30s at most. + while ! /usr/bin/docker info >/dev/null 2>&1; do + if [ $(date +%s) -ge "$END" ]; then + return 1 + fi + sleep 1 + done +} + +if ! wait_for_dockerd; then + echo "Failed to connect Docker daemon!" >&2 + exit 1 +fi + +exec /usr/bin/docker "$@"