Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions 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.2.1",
"version": "3.0.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 All @@ -22,13 +22,14 @@
},
"dockerDashComposeVersion": {
"type": "string",
"enum": [
"none",
"v1",
"v2"
"proposals": [
"latest",
"2.20.2",
"2.20",
"2"
],
"default": "v1",
"description": "Default version of Docker Compose (v1 or v2 or none)"
"default": "latest",
"description": "Select or enter a Docker Compose version"
},
"azureDnsAutoDetection": {
"type": "boolean",
Expand Down
82 changes: 20 additions & 62 deletions src/docker-in-docker/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

DOCKER_VERSION="${VERSION:-"latest"}" # The Docker/Moby Engine + CLI should match in version
USE_MOBY="${MOBY:-"true"}"
DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"v1"}" # v1 or v2 or none
DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"latest"}"
AZURE_DNS_AUTO_DETECTION="${AZUREDNSAUTODETECTION:-"true"}"
DOCKER_DEFAULT_ADDRESS_POOL="${DOCKERDEFAULTADDRESSPOOL}"
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
Expand Down Expand Up @@ -244,73 +244,31 @@ echo "Finished installing docker / moby!"

# If 'docker-compose' command is to be included
if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then
# Install Docker Compose if not already installed and is on a supported architecture
if type docker-compose > /dev/null 2>&1; then
echo "Docker Compose v1 already installed."
else
target_compose_arch="${architecture}"
if [ "${target_compose_arch}" = "amd64" ]; then
target_compose_arch="x86_64"
fi
if [ "${target_compose_arch}" != "x86_64" ]; then
# Use pip to get a version that runs on this architecture
check_packages python3-minimal python3-pip libffi-dev python3-venv
export PIPX_HOME=/usr/local/pipx
mkdir -p ${PIPX_HOME}
export PIPX_BIN_DIR=/usr/local/bin
export PYTHONUSERBASE=/tmp/pip-tmp
export PIP_CACHE_DIR=/tmp/pip-tmp/cache
pipx_bin=pipx
if ! type pipx > /dev/null 2>&1; then
pip3 install --disable-pip-version-check --no-cache-dir --user pipx
pipx_bin=/tmp/pip-tmp/bin/pipx
fi

set +e
${pipx_bin} install --pip-args '--no-cache-dir --force-reinstall' docker-compose
exit_code=$?
set -e

if [ ${exit_code} -ne 0 ]; then
# Temporary: https://github.com/devcontainers/features/issues/616
# See https://github.com/yaml/pyyaml/issues/601
echo "(*) Failed to install docker-compose via pipx. Trying via pip3..."

export PYTHONUSERBASE=/usr/local
pip3 install --disable-pip-version-check --no-cache-dir --user "Cython<3.0" pyyaml wheel docker-compose --no-build-isolation
fi
dockerComposeMajorVersion="$(echo ${DOCKER_DASH_COMPOSE_VERSION} | grep -oE '^[0-9]+' || echo '')"

rm -rf /tmp/pip-tmp
else
compose_v1_version="1"
find_version_from_git_tags compose_v1_version "https://github.com/docker/compose" "tags/"
echo "(*) Installing docker-compose ${compose_v1_version}..."
curl -fsSL "https://github.com/docker/compose/releases/download/${compose_v1_version}/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
fi
if [ "${dockerComposeMajorVersion}" = "1" ]; then
echo "(!) docker-compose v1 is not supported. To use docker-compose, set the DOCKER_DASH_COMPOSE_VERSION feature option to a v2 version (eg: 2.0.0)"
exit 1
fi

# Install docker-compose switch if not already installed - https://github.com/docker/compose-switch#manual-installation
current_v1_compose_path="$(which docker-compose)"
target_v1_compose_path="$(dirname "${current_v1_compose_path}")/docker-compose-v1"
if ! type compose-switch > /dev/null 2>&1; then
echo "(*) Installing compose-switch..."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the installation for docker compose-switch?

Reasoning: As tools will still use docker-compose, hence, we need a mapping. We could either use this switch or create an alias (like Docker desktop). For ease, we can keep the installation code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the need for compose-switch, based on it's description

Compose Switch is a replacement to the Compose V1 docker-compose (python) executable. It translates the command line into Compose V2 docker compose then run the latter.

During the installation, it already installs docker-compose-plugin from APT which enables $ docker compose, the part I'm updating installs https://github.com/docker/compose a.k.a Docker Compose v2 into /usr/local/bin/docker-compose

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During the installation, it already installs docker-compose-plugin from APT which enables $ docker compose, the part I'm updating installs https://github.com/docker/compose a.k.a Docker Compose v2 into /usr/local/bin/docker-compose

Installing docker compose v2 is perfect and that's what is required. In this context of the comment, it provides the docker compose command (notice the space here)

Can we keep the installation for docker compose-switch?

With the PR changes, tools/scripts which still use the docker-compose command (which was provided by v1) will fail. We don't have to install v1 to serve this scenario, however, we need to make sure that docker-compose command (notice the hyphen here) works.

We can achieve this by either installing the docker-compose switch or by adding a new alias. Even v2 Docker Desktop supports the use of docker-compose command (they use aliasing, so aliasing or compose switch anything is fine). So it feels right to add this support in the Feature as well.

Feel free to raise any questions/concerns!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, maybe I didn't articulate my point properly in my previous comment. I still don't think compose-switch is required here.

During installation, either docker-compose-plugin or moby-compose is installed from APT depending on if [ "${USE_MOBY}" = "true" ], this enables the use of $ docker compose

But also during installation, if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ], then it installs https://github.com/docker/compose, which to my understanding is actually the same binary as the package from APT, and this is installed into /usr/local/bin/docker-compose, so they are functionally the same, the difference being installation method

Packaged: https://docs.docker.com/compose/install/linux/#install-using-the-repository

VS

Manual: https://docs.docker.com/compose/install/standalone/

Which actually raises the question, is this step even required? Instead, is the right approach just to add an alias alias docker-compose='docker compose'?

Note:

Running the installation script with defaults results in

root ➜ /workspace $ which docker
/usr/bin/docker
root ➜ /workspace $ docker compose version
Docker Compose version 2.20.2+azure-1
root ➜ /workspace $ which docker-compose
/usr/local/bin/docker-compose
root ➜ /workspace $ docker-compose version
Docker Compose version v2.20.2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation.

Even v2 Docker Desktop supports the use of docker-compose command (they use aliasing, so aliasing or compose switch anything is fine).

Which actually raises the question, is this step even required? Instead, is the right approach just to add an alias alias docker-compose='docker compose'?

Yep, aliasing should be fine as well 👍

compose_switch_version="latest"
find_version_from_git_tags compose_switch_version "https://github.com/docker/compose-switch"
curl -fsSL "https://github.com/docker/compose-switch/releases/download/v${compose_switch_version}/docker-compose-linux-${architecture}" -o /usr/local/bin/compose-switch
chmod +x /usr/local/bin/compose-switch
# TODO: Verify checksum once available: https://github.com/docker/compose-switch/issues/11

# Setup v1 CLI as alternative in addition to compose-switch (which maps to v2)
mv "${current_v1_compose_path}" "${target_v1_compose_path}"
update-alternatives --install /usr/local/bin/docker-compose docker-compose /usr/local/bin/compose-switch 99
update-alternatives --install /usr/local/bin/docker-compose docker-compose "${target_v1_compose_path}" 1
fi
if [ "${DOCKER_DASH_COMPOSE_VERSION}" = "v1" ]; then
update-alternatives --set docker-compose "${target_v1_compose_path}"
if [ "${architecture}" = "amd64" ]; then
dockerComposeArch="x86_64"
elif [ "${architecture}" == "arm64" ]; then
dockerComposeArch="aarch64"
else
update-alternatives --set docker-compose /usr/local/bin/compose-switch
echo "(!) Architecture ${architecture} unsupported"
exit 1
fi

find_version_from_git_tags DOCKER_DASH_COMPOSE_VERSION "https://github.com/docker/compose" "refs/tags/v"

echo "(*) Installing docker-compose ${DOCKER_DASH_COMPOSE_VERSION}..."

curl --location https://github.com/docker/compose/releases/download/v${DOCKER_DASH_COMPOSE_VERSION}/docker-compose-linux-${dockerComposeArch} \
--output /usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose
fi

# If init file already exists, exit
Expand Down
9 changes: 4 additions & 5 deletions src/docker-outside-of-docker/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "docker-outside-of-docker",
"version": "1.3.0",
"version": "2.0.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.",
Expand All @@ -24,11 +24,10 @@
"type": "string",
"enum": [
"none",
"v1",
"v2"
"latest"
],
"default": "v2",
"description": "Compose version to use for docker-compose (v1 or v2 or none)"
"default": "latest",
"description": "Default version of Docker Compose (latest, none or specific version number e.g. 2.20.2)"
},
"installDockerBuildx": {
"type": "boolean",
Expand Down
53 changes: 17 additions & 36 deletions src/docker-outside-of-docker/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -218,44 +218,25 @@ fi

# If 'docker-compose' command is to be included
if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then
# Install Docker Compose if not already installed and is on a supported architecture
if type docker-compose > /dev/null 2>&1; then
echo "Docker Compose already installed."
elif [ "${DOCKER_DASH_COMPOSE_VERSION}" = "v1" ]; then
TARGET_COMPOSE_ARCH="$(uname -m)"
if [ "${TARGET_COMPOSE_ARCH}" = "amd64" ]; then
TARGET_COMPOSE_ARCH="x86_64"
fi
if [ "${TARGET_COMPOSE_ARCH}" != "x86_64" ]; then
# Use pip to get a version that runs on this architecture
check_packages python3-minimal python3-pip libffi-dev python3-venv
export PIPX_HOME=/usr/local/pipx
mkdir -p ${PIPX_HOME}
export PIPX_BIN_DIR=/usr/local/bin
export PYTHONUSERBASE=/tmp/pip-tmp
export PIP_CACHE_DIR=/tmp/pip-tmp/cache
pipx_bin=pipx
if ! type pipx > /dev/null 2>&1; then
pip3 install --disable-pip-version-check --no-cache-dir --user pipx
pipx_bin=/tmp/pip-tmp/bin/pipx
fi
${pipx_bin} install --pip-args '--no-cache-dir --force-reinstall' docker-compose
rm -rf /tmp/pip-tmp
else
compose_v1_version="1"
find_version_from_git_tags compose_v1_version "https://github.com/docker/compose" "tags/"
echo "(*) Installing docker-compose ${compose_v1_version}..."
curl -fsSL "https://github.com/docker/compose/releases/download/${compose_v1_version}/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
fi
if [ "${architecture}" == "amd64" ]; then
dockerComposeArch="x86_64"
elif [ "${architecture}" == "arm64" ]; then
dockerComposeArch="aarch64"
fi

if [ "${DOCKER_DASH_COMPOSE_VERSION}" == "latest" ]; then
docker_compose_version="latest"
find_version_from_git_tags docker_compose_version "https://github.com/docker/compose" "refs/tags/v"
else
echo "(*) Installing compose-switch as docker-compose..."
compose_switch_version="latest"
find_version_from_git_tags compose_switch_version "https://github.com/docker/compose-switch"
curl -fsSL "https://github.com/docker/compose-switch/releases/download/v${compose_switch_version}/docker-compose-linux-${architecture}" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
# TODO: Verify checksum once available: https://github.com/docker/compose-switch/issues/11
docker_compose_version="${DOCKER_DASH_COMPOSE_VERSION}"
fi

echo "(*) Installing docker-compose ${docker_compose_version}..."

curl --location https://github.com/docker/compose/releases/download/v${docker_compose_version}/docker-compose-linux-${dockerComposeArch} \
--output /usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose
fi

# Setup a docker group in the event the docker socket's group is not root
Expand Down
3 changes: 1 addition & 2 deletions test/docker-in-docker/docker_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ source dev-container-features-test-lib
check "docker-buildx" docker buildx version
check "docker-build" docker build ./

check "installs docker-compose v1 install" bash -c "type docker-compose"
check "installs compose-switch" bash -c "[[ -f /usr/local/bin/compose-switch ]]"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would be able to revert these changes after you add back compose switch installation!

check "installs docker-compose v2 install" bash -c "type docker-compose"

# Report result
reportResults
2 changes: 2 additions & 0 deletions test/docker-in-docker/docker_build_2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ source dev-container-features-test-lib
check "docker-buildx" docker buildx version
check "docker-build" docker build ./

check "installs docker-compose v2 install" bash -c "type docker-compose"

# Report result
reportResults
15 changes: 15 additions & 0 deletions test/docker-in-docker/docker_build_compose_v1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Definition specific tests
check "docker-buildx" docker buildx version
check "docker-build" docker build ./

check "not installing compose skips docker-compose v2 install" bash -c "! type docker-compose"

# Report result
reportResults
3 changes: 1 addition & 2 deletions test/docker-in-docker/docker_build_no_compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ source dev-container-features-test-lib
check "docker-buildx" docker buildx version
check "docker-build" docker build ./

check "not installing compose skips docker-compose v1 install" bash -c "! type docker-compose"
check "not installing compose skips compose-switch" bash -c "[[ ! -f /usr/local/bin/compose-switch ]]"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here! ^

check "not installing compose skips docker-compose v2 install" bash -c "! type docker-compose"

# Report result
reportResults
2 changes: 2 additions & 0 deletions test/docker-in-docker/docker_build_older.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ source dev-container-features-test-lib
check "docker-buildx" docker buildx version
check "docker-build" docker build ./

check "installs docker-compose v2 install" bash -c "type docker-compose"

# Report result
reportResults
16 changes: 12 additions & 4 deletions test/docker-in-docker/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"docker-in-docker": {
"version": "latest",
"moby": "false",
"dockerDashComposeVersion": "v2"
"dockerDashComposeVersion": "2"
}
},
"remoteUser": "node"
Expand All @@ -44,7 +44,7 @@
"version": "latest",
"installDockerBuildx": true,
"moby": "false",
"dockerDashComposeVersion": "v2"
"dockerDashComposeVersion": "2"
}
}
},
Expand All @@ -54,7 +54,7 @@
"docker-in-docker": {
"version": "20",
"moby": "false",
"dockerDashComposeVersion": "v2"
"dockerDashComposeVersion": "2"
}
},
"remoteUser": "node"
Expand All @@ -67,6 +67,14 @@
}
},
"remoteUser": "node"
},
"docker_build_compose_v1": {
"image": "mcr.microsoft.com/devcontainers/javascript-node:0-18",
"features": {
"docker-in-docker": {
"dockerDashComposeVersion": "1"
}
},
"remoteUser": "node"
}

}
2 changes: 1 addition & 1 deletion test/docker-outside-of-docker/docker_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ source dev-container-features-test-lib
check "docker-buildx" docker buildx version
check "docker-build" docker build ./

check "installs docker-compose v1 install" bash -c "type docker-compose"
check "installs docker-compose v2 install" bash -c "type docker-compose"

# Report result
reportResults
2 changes: 1 addition & 1 deletion test/docker-outside-of-docker/docker_build_no_compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ source dev-container-features-test-lib
check "docker-buildx" docker buildx version
check "docker-build" docker build ./

check "not installing compose skips docker-compose v1 install" bash -c "! type docker-compose"
check "not installing compose skips docker-compose v2 install" bash -c "! type docker-compose"

# Report result
reportResults
13 changes: 0 additions & 13 deletions test/docker-outside-of-docker/docker_dash_compose_v1.sh

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions test/docker-outside-of-docker/docker_dash_compose_v2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ source dev-container-features-test-lib
check "docker compose" bash -c "docker compose version | grep -E '2.[0-9]+.[0-9]+'"
check "docker-compose" bash -c "docker-compose --version | grep -E '2.[0-9]+.[0-9]+'"

check "installs compose-switch as docker-compose" bash -c "[[ -f /usr/local/bin/docker-compose ]]"

# Report result
reportResults
23 changes: 2 additions & 21 deletions test/docker-outside-of-docker/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-20.04",
"features": {
"docker-outside-of-docker": {
"moby": true
"moby": true,
"dockerDashComposeVersion": "v2"
}
},
"containerUser": "vscode"
Expand All @@ -76,26 +77,6 @@
},
"containerUser": "vscode"
},
"docker_dash_compose_v1": {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would be able to revert these changes after you add back compose switch installation!

Can we add a test scenario which validates specific version/semver changes? Thanks!

"image": "mcr.microsoft.com/devcontainers/base:ubuntu-20.04",
"features": {
"docker-outside-of-docker": {
"moby": false,
"dockerDashComposeVersion": "v1"
}
},
"containerUser": "vscode"
},
"docker_dash_compose_v1_moby": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-20.04",
"features": {
"docker-outside-of-docker": {
"moby": true,
"dockerDashComposeVersion": "v1"
}
},
"containerUser": "vscode"
},
"docker_dash_compose_v2": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-20.04",
"features": {
Expand Down