aboutsummaryrefslogtreecommitdiff
path: root/src/docker-in-docker
diff options
context:
space:
mode:
authorSamruddhi Khandale <skhandale@microsoft.com>2023-08-24 22:31:40 +0300
committerGitHub <noreply@github.com>2023-08-24 22:31:40 +0300
commit0cf690ee14279d9e7ae5e1308950d6067d3aba81 (patch)
treea65d55d08b71b8432456aff80cf3457af98b0fba /src/docker-in-docker
parenta08434f2b18627f31107a4ef6ab4f578a92aeaec (diff)
[docker in docker] Adds retries for docker daemon startup and cgroup nesting (#669)feature_docker-in-docker_2.4.0
* adds retry logic * adds stress test workflow * Adds cgroup retries * update workflow * move sleep cmd * update test * cleanup
Diffstat (limited to 'src/docker-in-docker')
-rw-r--r--src/docker-in-docker/devcontainer-feature.json2
-rwxr-xr-xsrc/docker-in-docker/install.sh102
2 files changed, 74 insertions, 30 deletions
diff --git a/src/docker-in-docker/devcontainer-feature.json b/src/docker-in-docker/devcontainer-feature.json
index 2afdd11..edfaa1f 100644
--- a/src/docker-in-docker/devcontainer-feature.json
+++ b/src/docker-in-docker/devcontainer-feature.json
@@ -1,6 +1,6 @@
{
"id": "docker-in-docker",
- "version": "2.3.1",
+ "version": "2.4.0",
"name": "Docker (Docker-in-Docker)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/docker-in-docker",
"description": "Create child containers *inside* a container, independent from the host's docker instance. Installs Docker extension in the container along with needed CLIs.",
diff --git a/src/docker-in-docker/install.sh b/src/docker-in-docker/install.sh
index bdef126..a0d4a94 100755
--- a/src/docker-in-docker/install.sh
+++ b/src/docker-in-docker/install.sh
@@ -367,7 +367,7 @@ dockerd_start="AZURE_DNS_AUTO_DETECTION=${AZURE_DNS_AUTO_DETECTION} DOCKER_DEFAU
find /run /var/run -iname 'docker*.pid' -delete || :
find /run /var/run -iname 'container*.pid' -delete || :
- ## Dind wrapper script from docker team, adapted to a function
+ # -- Start: dind wrapper script --
# Maintained: https://github.com/moby/moby/blob/master/hack/dind
export container=docker
@@ -384,31 +384,52 @@ dockerd_start="AZURE_DNS_AUTO_DETECTION=${AZURE_DNS_AUTO_DETECTION} DOCKER_DEFAU
mount -t tmpfs none /tmp
fi
- # cgroup v2: enable nesting
- if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
- # move the processes from the root group to the /init group,
- # otherwise writing subtree_control fails with EBUSY.
- # An error during moving non-existent process (i.e., "cat") is ignored.
- mkdir -p /sys/fs/cgroup/init
- xargs -rn1 < /sys/fs/cgroup/cgroup.procs > /sys/fs/cgroup/init/cgroup.procs || :
- # enable controllers
- sed -e 's/ / +/g' -e 's/^/+/' < /sys/fs/cgroup/cgroup.controllers \
- > /sys/fs/cgroup/cgroup.subtree_control
- fi
- ## Dind wrapper over.
+ set_cgroup_nesting()
+ {
+ # cgroup v2: enable nesting
+ if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
+ # move the processes from the root group to the /init group,
+ # otherwise writing subtree_control fails with EBUSY.
+ # An error during moving non-existent process (i.e., "cat") is ignored.
+ mkdir -p /sys/fs/cgroup/init
+ xargs -rn1 < /sys/fs/cgroup/cgroup.procs > /sys/fs/cgroup/init/cgroup.procs || :
+ # enable controllers
+ sed -e 's/ / +/g' -e 's/^/+/' < /sys/fs/cgroup/cgroup.controllers \
+ > /sys/fs/cgroup/cgroup.subtree_control
+ fi
+ }
+
+ # Set cgroup nesting, retrying if necessary
+ retry_cgroup_nesting=0
+
+ until [ "${retry_cgroup_nesting}" -eq "5" ];
+ do
+ set +e
+ set_cgroup_nesting
+
+ if [ $? -ne 0 ]; then
+ echo "(*) cgroup v2: Failed to enable nesting, retrying..."
+ else
+ break
+ fi
+
+ retry_cgroup_nesting=`expr $retry_cgroup_nesting + 1`
+ set -e
+ done
+
+ # -- End: dind wrapper script --
# Handle DNS
set +e
- cat /etc/resolv.conf | grep -i 'internal.cloudapp.net'
- if [ $? -eq 0 ] && [ "${AZURE_DNS_AUTO_DETECTION}" = "true" ]
- then
- echo "Setting dockerd Azure DNS."
- CUSTOMDNS="--dns 168.63.129.16"
- else
- echo "Not setting dockerd DNS manually."
- CUSTOMDNS=""
- fi
-
+ cat /etc/resolv.conf | grep -i 'internal.cloudapp.net' > /dev/null 2>&1
+ if [ $? -eq 0 ] && [ "${AZURE_DNS_AUTO_DETECTION}" = "true" ]
+ then
+ echo "Setting dockerd Azure DNS."
+ CUSTOMDNS="--dns 168.63.129.16"
+ else
+ echo "Not setting dockerd DNS manually."
+ CUSTOMDNS=""
+ fi
set -e
if [ -z "$DOCKER_DEFAULT_ADDRESS_POOL" ]
@@ -423,12 +444,35 @@ dockerd_start="AZURE_DNS_AUTO_DETECTION=${AZURE_DNS_AUTO_DETECTION} DOCKER_DEFAU
INNEREOF
)"
-# Start using sudo if not invoked as root
-if [ "$(id -u)" -ne 0 ]; then
- sudo /bin/sh -c "${dockerd_start}"
-else
- eval "${dockerd_start}"
-fi
+retry_docker_start_count=0
+docker_ok="false"
+
+until [ "${docker_ok}" = "true" ] || [ "${retry_docker_start_count}" -eq "5" ];
+do
+ # Start using sudo if not invoked as root
+ if [ "$(id -u)" -ne 0 ]; then
+ sudo /bin/sh -c "${dockerd_start}"
+ else
+ eval "${dockerd_start}"
+ fi
+
+ retry_count=0
+ until [ "${docker_ok}" = "true" ] || [ "${retry_count}" -eq "5" ];
+ do
+ sleep 1s
+ set +e
+ docker info > /dev/null 2>&1 && docker_ok="true"
+ set -e
+
+ retry_count=`expr $retry_count + 1`
+ done
+
+ if [ "${docker_ok}" != "true" ]; then
+ echo "(*) Failed to start docker, retrying..."
+ fi
+
+ retry_docker_start_count=`expr $retry_docker_start_count + 1`
+done
# Execute whatever commands were passed in (if any). This allows us
# to set this script to ENTRYPOINT while still executing the default CMD.