aboutsummaryrefslogtreecommitdiff
path: root/src/docker-outside-of-docker
diff options
context:
space:
mode:
authorSamruddhi Khandale <skhandale@microsoft.com>2023-03-09 02:30:59 +0300
committerGitHub <noreply@github.com>2023-03-09 02:30:59 +0300
commitde1e634a6755e10b27e52ad4e0aa44f025540074 (patch)
tree5e3b4365a10465e9e0dfb3549fc64e996a1e73fc /src/docker-outside-of-docker
parentfe449253f138f3c028627d3e9cc3d500d650b159 (diff)
Docker fix - BuildKit is enabled but the buildx component is missing or broken (#478)feature_docker-outside-of-docker_1.1.0feature_docker-in-docker_2.1.0
* Docker fix - BuildKit is enabled but the buildx component is missing or broken * nit * fix test
Diffstat (limited to 'src/docker-outside-of-docker')
-rw-r--r--src/docker-outside-of-docker/devcontainer-feature.json7
-rwxr-xr-xsrc/docker-outside-of-docker/install.sh31
2 files changed, 31 insertions, 7 deletions
diff --git a/src/docker-outside-of-docker/devcontainer-feature.json b/src/docker-outside-of-docker/devcontainer-feature.json
index 1f3ff4e..79bc9fe 100644
--- a/src/docker-outside-of-docker/devcontainer-feature.json
+++ b/src/docker-outside-of-docker/devcontainer-feature.json
@@ -1,6 +1,6 @@
{
"id": "docker-outside-of-docker",
- "version": "1.0.10",
+ "version": "1.1.0",
"name": "Docker (docker-outside-of-docker)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/docker-outside-of-docker",
"description": "Re-use the host docker socket, adding the Docker CLI to a container. Feature invokes a script to enable using a forwarded Docker socket within a container to run Docker commands.",
@@ -28,6 +28,11 @@
],
"default": "v1",
"description": "Compose version to use for docker-compose (v1 or v2)"
+ },
+ "installDockerBuildx": {
+ "type": "boolean",
+ "default": true,
+ "description": "Install Docker Buildx"
}
},
"entrypoint": "/usr/local/share/docker-init.sh",
diff --git a/src/docker-outside-of-docker/install.sh b/src/docker-outside-of-docker/install.sh
index dc5a903..6352410 100755
--- a/src/docker-outside-of-docker/install.sh
+++ b/src/docker-outside-of-docker/install.sh
@@ -15,6 +15,7 @@ ENABLE_NONROOT_DOCKER="${ENABLE_NONROOT_DOCKER:-"true"}"
SOURCE_SOCKET="${SOURCE_SOCKET:-"/var/run/docker-host.sock"}"
TARGET_SOCKET="${TARGET_SOCKET:-"/var/run/docker.sock"}"
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
+INSTALL_DOCKER_BUILDX="${INSTALLDOCKERBUILDX:-"true"}"
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES="buster bullseye bionic focal jammy"
@@ -116,7 +117,7 @@ find_version_from_git_tags() {
export DEBIAN_FRONTEND=noninteractive
# Install dependencies
-check_packages apt-transport-https curl ca-certificates gnupg2 dirmngr
+check_packages apt-transport-https curl ca-certificates gnupg2 dirmngr wget
if ! type git > /dev/null 2>&1; then
check_packages git
fi
@@ -254,6 +255,29 @@ else
update-alternatives --set docker-compose /usr/local/bin/compose-switch
fi
+# Setup a docker group in the event the docker socket's group is not root
+if ! grep -qE '^docker:' /etc/group; then
+ groupadd --system docker
+fi
+usermod -aG docker "${USERNAME}"
+
+if [ "${INSTALL_DOCKER_BUILDX}" = "true" ]; then
+ buildx_version="latest"
+ find_version_from_git_tags buildx_version "https://github.com/docker/buildx" "refs/tags/v"
+
+ echo "(*) Installing buildx ${buildx_version}..."
+ buildx_file_name="buildx-v${buildx_version}.linux-${architecture}"
+ cd /tmp && wget "https://github.com/docker/buildx/releases/download/v${buildx_version}/${buildx_file_name}"
+
+ mkdir -p ${_REMOTE_USER_HOME}/.docker/cli-plugins
+ mv ${buildx_file_name} ${_REMOTE_USER_HOME}/.docker/cli-plugins/docker-buildx
+ chmod +x ${_REMOTE_USER_HOME}/.docker/cli-plugins/docker-buildx
+
+ chown -R "${USERNAME}:docker" "${_REMOTE_USER_HOME}/.docker"
+ chmod -R g+r+w "${_REMOTE_USER_HOME}/.docker"
+ find "${_REMOTE_USER_HOME}/.docker" -type d -print0 | xargs -n 1 -0 chmod g+s
+fi
+
# If init file already exists, exit
if [ -f "/usr/local/share/docker-init.sh" ]; then
# Clean up
@@ -277,11 +301,6 @@ if [ "${ENABLE_NONROOT_DOCKER}" = "false" ] || [ "${USERNAME}" = "root" ]; then
exit 0
fi
-# Setup a docker group in the event the docker socket's group is not root
-if ! grep -qE '^docker:' /etc/group; then
- groupadd --system docker
-fi
-usermod -aG docker "${USERNAME}"
DOCKER_GID="$(grep -oP '^docker:x:\K[^:]+' /etc/group)"
# If enabling non-root access and specified user is found, setup socat and add script