diff --git a/src/docker-in-docker/devcontainer-feature.json b/src/docker-in-docker/devcontainer-feature.json index 2710a2e32..ae99cb12b 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": "4.0.0", + "version": "4.1.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.", @@ -47,6 +47,12 @@ "proposals": [], "description": "Define default address pools for Docker networks. e.g. base=192.168.0.0/16,size=24" }, + "dockerHostGatewayIP": { + "type": "string", + "default": "", + "proposals": [], + "description": "Set the IP used to resolve the special 'host-gateway' value in --add-host. e.g. 192.168.0.1" + }, "installDockerBuildx": { "type": "boolean", "default": true, diff --git a/src/docker-in-docker/install.sh b/src/docker-in-docker/install.sh index dbef9ae32..5c91452f1 100755 --- a/src/docker-in-docker/install.sh +++ b/src/docker-in-docker/install.sh @@ -14,6 +14,7 @@ MOBY_BUILDX_VERSION="${MOBYBUILDXVERSION:-"latest"}" DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"latest"}" #v1, v2, latest or none AZURE_DNS_AUTO_DETECTION="${AZUREDNSAUTODETECTION:-"true"}" DOCKER_DEFAULT_ADDRESS_POOL="${DOCKERDEFAULTADDRESSPOOL:-""}" +DOCKER_HOST_GATEWAY_IP="${DOCKERHOSTGATEWAYIP:-""}" USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}" INSTALL_DOCKER_BUILDX="${INSTALLDOCKERBUILDX:-"true"}" INSTALL_DOCKER_COMPOSE_SWITCH="${INSTALLDOCKERCOMPOSESWITCH:-"false"}" @@ -973,6 +974,7 @@ set -e AZURE_DNS_AUTO_DETECTION=${AZURE_DNS_AUTO_DETECTION} DOCKER_DEFAULT_ADDRESS_POOL=${DOCKER_DEFAULT_ADDRESS_POOL} +DOCKER_HOST_GATEWAY_IP=${DOCKER_HOST_GATEWAY_IP} DOCKER_DEFAULT_IP6_TABLES=${DOCKER_DEFAULT_IP6_TABLES} EOF @@ -1001,7 +1003,7 @@ fi 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} DOCKER_DEFAULT_IP6_TABLES=${DOCKER_DEFAULT_IP6_TABLES} $(cat << 'INNEREOF' +dockerd_start="AZURE_DNS_AUTO_DETECTION=${AZURE_DNS_AUTO_DETECTION} DOCKER_DEFAULT_ADDRESS_POOL=${DOCKER_DEFAULT_ADDRESS_POOL} DOCKER_HOST_GATEWAY_IP=${DOCKER_HOST_GATEWAY_IP} DOCKER_DEFAULT_IP6_TABLES=${DOCKER_DEFAULT_IP6_TABLES} $(cat << 'INNEREOF' # explicitly remove dockerd and containerd PID file to ensure that it can start properly if it was stopped uncleanly find /run /var/run -iname 'docker*.pid' -delete || : find /run /var/run -iname 'container*.pid' -delete || : @@ -1078,6 +1080,13 @@ dockerd_start="AZURE_DNS_AUTO_DETECTION=${AZURE_DNS_AUTO_DETECTION} DOCKER_DEFAU DEFAULT_ADDRESS_POOL="--default-address-pool $DOCKER_DEFAULT_ADDRESS_POOL" fi + if [ -z "$DOCKER_HOST_GATEWAY_IP" ] + then + HOST_GATEWAY_IP="" + else + HOST_GATEWAY_IP="--host-gateway-ip $DOCKER_HOST_GATEWAY_IP" + fi + # Start our own containerd so it picks up /etc/containerd/config.toml # (notably the disabled_plugins entry for the erofs snapshotter, see @@ -1113,7 +1122,7 @@ dockerd_start="AZURE_DNS_AUTO_DETECTION=${AZURE_DNS_AUTO_DETECTION} DOCKER_DEFAU fi # Start docker/moby engine - ( dockerd $DOCKERD_CONTAINERD_ARG $CUSTOMDNS $DEFAULT_ADDRESS_POOL $DOCKER_DEFAULT_IP6_TABLES > /tmp/dockerd.log 2>&1 ) & + ( dockerd $DOCKERD_CONTAINERD_ARG $CUSTOMDNS $DEFAULT_ADDRESS_POOL $HOST_GATEWAY_IP $DOCKER_DEFAULT_IP6_TABLES > /tmp/dockerd.log 2>&1 ) & INNEREOF )" diff --git a/test/docker-in-docker/dockerHostGatewayIP.sh b/test/docker-in-docker/dockerHostGatewayIP.sh new file mode 100755 index 000000000..88ca752f0 --- /dev/null +++ b/test/docker-in-docker/dockerHostGatewayIP.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +check "host gateway ip setting set" ps -ax | grep -v grep | grep -E "dockerd.+--host-gateway-ip 192.168.0.1" + +# Report result +reportResults diff --git a/test/docker-in-docker/scenarios.json b/test/docker-in-docker/scenarios.json index a4ee2a3b0..302f5bcee 100644 --- a/test/docker-in-docker/scenarios.json +++ b/test/docker-in-docker/scenarios.json @@ -92,6 +92,15 @@ } } }, + "dockerHostGatewayIP": { + "image": "mcr.microsoft.com/vscode/devcontainers/javascript-node:0-18", + "remoteUser": "node", + "features": { + "docker-in-docker": { + "dockerHostGatewayIP": "192.168.0.1" + } + } + }, "azureDnsAutoDetectionEnabled": { "image": "mcr.microsoft.com/vscode/devcontainers/javascript-node:0-18", "remoteUser": "node",