Skip to content

Commit

Permalink
Add a wrapper for docker that waits for daemon
Browse files Browse the repository at this point in the history
See linked gitlab issue for more info:
https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27300
  • Loading branch information
antti-mikael committed Feb 3, 2024
1 parent afe7a0c commit 96baa25
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
21 changes: 21 additions & 0 deletions utils/docker-wrapper.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit 96baa25

Please sign in to comment.