Skip to content

Commit d926879

Browse files
[docker-in-docker] - toggle ip6tables settings value as option (#1068)
* [docker-in-docker] - toggle ip6tables settings value as option * Update src/docker-in-docker/devcontainer-feature.json Co-authored-by: Samruddhi Khandale <[email protected]> * Update src/docker-in-docker/devcontainer-feature.json Co-authored-by: Samruddhi Khandale <[email protected]> * ip6tables - can be toggled * changes as requested * change to add test file.. * changes for docker_build_older test passing * misc change * CHANGE * chg * minor change to make tests pass * for sh compatibility * change for version * small change * few imp. changes * few changes * for test passing * minor commit * version added to a test scenario * changes * LOGIC was moved outside the init file for faster initialization times * changes * logic updated ! * chg * default value to be null * changes as suggested in review comments.. * by mistake * another small change * requested changes in comments (review pr) * change as requested * changes as suggested in review comments * Update src/docker-in-docker/install.sh Co-authored-by: Samruddhi Khandale <[email protected]> --------- Co-authored-by: Samruddhi Khandale <[email protected]>
1 parent b0667c5 commit d926879

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

src/docker-in-docker/devcontainer-feature.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "docker-in-docker",
3-
"version": "2.11.0",
3+
"version": "2.12.0",
44
"name": "Docker (Docker-in-Docker)",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/docker-in-docker",
66
"description": "Create child containers *inside* a container, independent from the host's docker instance. Installs Docker extension in the container along with needed CLIs.",
@@ -55,6 +55,11 @@
5555
"type": "boolean",
5656
"default": true,
5757
"description": "Install Compose Switch (provided docker compose is available) which is a replacement to the Compose V1 docker-compose (python) executable. It translates the command line into Compose V2 docker compose then runs the latter."
58+
},
59+
"disableIp6tables": {
60+
"type": "boolean",
61+
"default": false,
62+
"description": "Disable ip6tables (this option is only applicable for Docker versions 27 and greater)"
5863
}
5964
},
6065
"entrypoint": "/usr/local/share/docker-init.sh",

src/docker-in-docker/install.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ INSTALL_DOCKER_COMPOSE_SWITCH="${INSTALLDOCKERCOMPOSESWITCH:-"true"}"
2020
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
2121
DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES="bookworm buster bullseye bionic focal jammy noble"
2222
DOCKER_LICENSED_ARCHIVE_VERSION_CODENAMES="bookworm buster bullseye bionic focal hirsute impish jammy noble"
23+
DISABLE_IP6_TABLES="${DISABLEIP6TABLES:-false}"
2324

2425
# Default: Exit on any failure.
2526
set -e
@@ -468,6 +469,23 @@ if [ "${INSTALL_DOCKER_BUILDX}" = "true" ]; then
468469
find "${docker_home}" -type d -print0 | xargs -n 1 -0 chmod g+s
469470
fi
470471

472+
DOCKER_DEFAULT_IP6_TABLES=""
473+
if [ "$DISABLE_IP6_TABLES" == true ]; then
474+
requested_version=""
475+
# checking whether the version requested either is in semver format or just a number denoting the major version
476+
# and, extracting the major version number out of the two scenarios
477+
semver_regex="^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$"
478+
if echo "$DOCKER_VERSION" | grep -Eq $semver_regex; then
479+
requested_version=$(echo $DOCKER_VERSION | cut -d. -f1)
480+
elif echo "$DOCKER_VERSION" | grep -Eq "^[1-9][0-9]*$"; then
481+
requested_version=$DOCKER_VERSION
482+
fi
483+
if [ "$DOCKER_VERSION" = "latest" ] || [[ -n "$requested_version" && "$requested_version" -ge 27 ]] ; then
484+
DOCKER_DEFAULT_IP6_TABLES="--ip6tables=false"
485+
echo "(!) As requested, passing '${DOCKER_DEFAULT_IP6_TABLES}'"
486+
fi
487+
fi
488+
471489
tee /usr/local/share/docker-init.sh > /dev/null \
472490
<< EOF
473491
#!/bin/sh
@@ -480,11 +498,12 @@ set -e
480498
481499
AZURE_DNS_AUTO_DETECTION=${AZURE_DNS_AUTO_DETECTION}
482500
DOCKER_DEFAULT_ADDRESS_POOL=${DOCKER_DEFAULT_ADDRESS_POOL}
501+
DOCKER_DEFAULT_IP6_TABLES=${DOCKER_DEFAULT_IP6_TABLES}
483502
EOF
484503

485504
tee -a /usr/local/share/docker-init.sh > /dev/null \
486505
<< 'EOF'
487-
dockerd_start="AZURE_DNS_AUTO_DETECTION=${AZURE_DNS_AUTO_DETECTION} DOCKER_DEFAULT_ADDRESS_POOL=${DOCKER_DEFAULT_ADDRESS_POOL} $(cat << 'INNEREOF'
506+
dockerd_start="AZURE_DNS_AUTO_DETECTION=${AZURE_DNS_AUTO_DETECTION} DOCKER_DEFAULT_ADDRESS_POOL=${DOCKER_DEFAULT_ADDRESS_POOL} DOCKER_DEFAULT_IP6_TABLES=${DOCKER_DEFAULT_IP6_TABLES} $(cat << 'INNEREOF'
488507
# explicitly remove dockerd and containerd PID file to ensure that it can start properly if it was stopped uncleanly
489508
find /run /var/run -iname 'docker*.pid' -delete || :
490509
find /run /var/run -iname 'container*.pid' -delete || :
@@ -562,7 +581,7 @@ dockerd_start="AZURE_DNS_AUTO_DETECTION=${AZURE_DNS_AUTO_DETECTION} DOCKER_DEFAU
562581
fi
563582
564583
# Start docker/moby engine
565-
( dockerd $CUSTOMDNS $DEFAULT_ADDRESS_POOL > /tmp/dockerd.log 2>&1 ) &
584+
( dockerd $CUSTOMDNS $DEFAULT_ADDRESS_POOL $DOCKER_DEFAULT_IP6_TABLES > /tmp/dockerd.log 2>&1 ) &
566585
INNEREOF
567586
)"
568587
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
ip6tablesCheck() {
9+
if command -v ip6tables > /dev/null 2>&1; then
10+
if ip6tables -L > /dev/null 2>&1; then
11+
echo "✔️ ip6tables is enabled."
12+
else
13+
echo "❌ ip6tables is disabled."
14+
fi
15+
else
16+
echo "❕ip6tables command not found. ❕"
17+
fi
18+
}
19+
20+
check "ip6tables" ip6tablesCheck
21+
check "ip6tables check" bash -c "docker network inspect bridge"
22+
check "docker-build" docker build ./
23+
24+
reportResults

test/docker-in-docker/scenarios.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
}
99
}
1010
},
11+
"dockerIp6tablesDisabledTest": {
12+
"image": "ubuntu:focal",
13+
"features": {
14+
"docker-in-docker": {
15+
"version": "27.0.3",
16+
"disableIp6tables": true
17+
}
18+
}
19+
},
1120
"dockerDefaultAddressPool": {
1221
"image": "mcr.microsoft.com/vscode/devcontainers/javascript-node:0-18",
1322
"remoteUser": "node",

0 commit comments

Comments
 (0)