Skip to content

Commit

Permalink
Docker-in-docker: Updates docker-init with "pkill" (#711)
Browse files Browse the repository at this point in the history
* Docker-in-docker: Updates docker-init with "pkill"

* pkill only if container didn't start at first

* pkill with condition

* add back sudo_if
  • Loading branch information
samruddhikhandale authored Sep 29, 2023
1 parent cf92754 commit 04cb7d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/docker-in-docker/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "docker-in-docker",
"version": "2.5.0",
"version": "2.6.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.",
Expand Down
15 changes: 14 additions & 1 deletion src/docker-in-docker/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,9 @@ EOF
tee -a /usr/local/share/docker-init.sh > /dev/null \
<< 'EOF'
dockerd_start="AZURE_DNS_AUTO_DETECTION=${AZURE_DNS_AUTO_DETECTION} DOCKER_DEFAULT_ADDRESS_POOL=${DOCKER_DEFAULT_ADDRESS_POOL} $(cat << 'INNEREOF'
# Stop dockerd and containerd in case they are already running
docker info > /dev/null 2>&1 && pkill dockerd && pkill containerd
# explicitly remove dockerd and containerd PID file to ensure that it can start properly if it was stopped uncleanly
# ie: docker kill <ID>
find /run /var/run -iname 'docker*.pid' -delete || :
find /run /var/run -iname 'container*.pid' -delete || :
Expand Down Expand Up @@ -444,6 +445,16 @@ dockerd_start="AZURE_DNS_AUTO_DETECTION=${AZURE_DNS_AUTO_DETECTION} DOCKER_DEFAU
INNEREOF
)"
sudo_if() {
COMMAND="$*"
if [ "$(id -u)" -ne 0 ]; then
sudo $COMMAND
else
$COMMAND
fi
}
retry_docker_start_count=0
docker_ok="false"
Expand All @@ -469,6 +480,8 @@ do
if [ "${docker_ok}" != "true" ]; then
echo "(*) Failed to start docker, retrying..."
sudo_if pkill dockerd
sudo_if pkill containerd
fi
retry_docker_start_count=`expr $retry_docker_start_count + 1`
Expand Down

0 comments on commit 04cb7d1

Please sign in to comment.