Skip to content

Commit 2b69559

Browse files
Made changes to docker-in-docker install script to work for fedora
1 parent 66385f3 commit 2b69559

3 files changed

Lines changed: 152 additions & 14 deletions

File tree

src/docker-in-docker/install.sh

Lines changed: 106 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
DOCKER_VERSION="${VERSION:-"latest"}" # The Docker/Moby Engine + CLI should match in version
1212
USE_MOBY="${MOBY:-"true"}"
1313
MOBY_BUILDX_VERSION="${MOBYBUILDXVERSION:-"latest"}"
14-
DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"v2"}" #v1, v2 or none
14+
DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"latest"}" #v1, v2 or none
1515
AZURE_DNS_AUTO_DETECTION="${AZUREDNSAUTODETECTION:-"true"}"
1616
DOCKER_DEFAULT_ADDRESS_POOL="${DOCKERDEFAULTADDRESSPOOL:-""}"
1717
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
@@ -62,19 +62,37 @@ fi
6262

6363
apt_get_update()
6464
{
65-
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
65+
. /etc/os-release
66+
if [ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ]; then
67+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
6668
echo "Running apt-get update..."
6769
apt-get update -y
70+
apt-get install -y gnupg curl
71+
apt-get -y install --no-install-recommends "$@"
72+
fi
6873
fi
6974
}
7075

7176
# Checks if packages are installed and installs them if not
7277
check_packages() {
78+
79+
if [ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ] || ["$ID_LIKE" = "debian"]; then
7380
if ! dpkg -s "$@" > /dev/null 2>&1; then
7481
apt_get_update
7582
apt-get -y install --no-install-recommends "$@"
7683
fi
84+
elif [ "$ID" = "fedora" ] || [ "$ID" = "centos" ] || [ "$ID_LIKE" == "rhel" ]; then
85+
if ! dnf list installed "$@" > /dev/null 2>&1; then
86+
dnf -y install "$@"
87+
fi
88+
fi
89+
7790
}
91+
# Install dependencies for fedora
92+
if ! command -v git wget which&> /dev/null; then
93+
echo "packages not found. Installing..."
94+
dnf install -y git wget which curl jq
95+
fi
7896

7997
# Figure out correct version of a three part version number is not passed
8098
find_version_from_git_tags() {
@@ -191,8 +209,21 @@ export DEBIAN_FRONTEND=noninteractive
191209

192210
# Source /etc/os-release to get OS info
193211
. /etc/os-release
194-
# Fetch host/container arch.
195-
architecture="$(dpkg --print-architecture)"
212+
# Fetch host/container architecture
213+
if [ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ]; then
214+
architecture="$(dpkg --print-architecture)"
215+
elif [ "$ID" = "fedora" ] || [ "$ID_LIKE" = "rhel" ]; then
216+
architecture="$(uname -m)"
217+
case "$architecture" in
218+
x86_64) architecture="amd64" ;;
219+
aarch64) architecture="arm64" ;;
220+
*) echo "Unsupported architecture: $architecture"; exit 1 ;;
221+
esac
222+
else
223+
echo "Unsupported operating system: $ID"
224+
exit 1
225+
fi
226+
196227

197228
# Check if distro is supported
198229
if [ "${USE_MOBY}" = "true" ]; then
@@ -217,15 +248,16 @@ if ! type git > /dev/null 2>&1; then
217248
check_packages git
218249
fi
219250

251+
252+
220253
# Swap to legacy iptables for compatibility
221254
if type iptables-legacy > /dev/null 2>&1; then
222255
update-alternatives --set iptables /usr/sbin/iptables-legacy
223256
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
224257
fi
225258

226-
227-
228259
# Set up the necessary apt repos (either Microsoft's or Docker's)
260+
if [ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ]; then
229261
if [ "${USE_MOBY}" = "true" ]; then
230262

231263
# Name of open source engine/cli
@@ -247,7 +279,7 @@ fi
247279

248280
# Refresh apt lists
249281
apt-get update
250-
282+
fi
251283
# Soft version matching
252284
if [ "${DOCKER_VERSION}" = "latest" ] || [ "${DOCKER_VERSION}" = "lts" ] || [ "${DOCKER_VERSION}" = "stable" ]; then
253285
# Empty, meaning grab whatever "latest" is in apt repo
@@ -293,33 +325,93 @@ if [ "${USE_MOBY}" = "true" ]; then
293325
fi
294326
fi
295327

328+
install_docker_or_moby() {
329+
# Check for the OS type
330+
if [ -f /etc/os-release ]; then
331+
. /etc/os-release
332+
fi
333+
334+
# Set Fedora version for repository URL
335+
RELEASE_VER=$(sed 's/\..*//' /etc/fedora-release)
336+
337+
# Check if the user wants to use Moby (open-source version of Docker)
338+
if [ "${USE_MOBY}" == "true" ]; then
339+
echo "Setting up Moby repository for Fedora..."
340+
# Add Moby repository (Microsoft)
341+
echo "[microsoft]" > /etc/yum.repos.d/microsoft.repo
342+
echo "name=Microsoft Packages" >> /etc/yum.repos.d/microsoft.repo
343+
echo "baseurl=https://packages.microsoft.com/yumrepos/microsoft-fedora$RELEASE_VER" >> /etc/yum.repos.d/microsoft.repo
344+
echo "enabled=1" >> /etc/yum.repos.d/microsoft.repo
345+
echo "gpgcheck=1" >> /etc/yum.repos.d/microsoft.repo
346+
echo "gpgkey=https://packages.microsoft.com/keys/microsoft.asc" >> /etc/yum.repos.d/microsoft.repo
347+
348+
# Install Moby Engine and CLI
349+
echo "Installing Moby packages..."
350+
sudo dnf install -y moby-engine moby-cli moby-buildx --skip-unavailable
351+
352+
else
353+
echo "Setting up Docker repository for Fedora..."
354+
# Add Docker repository (Docker CE)
355+
echo "[docker-ce-stable]" > /etc/yum.repos.d/docker.repo
356+
echo "name=Docker CE Stable - Fedora $RELEASE_VER" >> /etc/yum.repos.d/docker.repo
357+
echo "baseurl=https://download.docker.com/linux/fedora/$RELEASE_VER/stable/\$basearch" >> /etc/yum.repos.d/docker.repo
358+
echo "enabled=1" >> /etc/yum.repos.d/docker.repo
359+
echo "gpgcheck=1" >> /etc/yum.repos.d/docker.repo
360+
echo "gpgkey=https://download.docker.com/linux/fedora/gpg" >> /etc/yum.repos.d/docker.repo
361+
362+
# Install Docker CE
363+
echo "Installing Docker CE..."
364+
dnf install -y docker-ce docker-ce-cli containerd.io
365+
fi
366+
367+
# Enable and start Docker/Moby
368+
echo "Enabling and starting Docker/Moby service..."
369+
systemctl enable docker
370+
371+
# Add the current user to the docker group
372+
echo "Adding user to Docker group..."
373+
usermod -aG docker ${USERNAME}
374+
375+
# Clean up DNF cache
376+
echo "Cleaning up DNF cache..."
377+
dnf clean all
378+
379+
# Final message
380+
echo "Docker/Moby installation completed successfully!"
381+
echo "Please log out and log back in to apply group changes."
382+
}
296383
# Install Docker / Moby CLI if not already installed
297384
if type docker > /dev/null 2>&1 && type dockerd > /dev/null 2>&1; then
298385
echo "Docker / Moby CLI and Engine already installed."
299386
else
300-
if [ "${USE_MOBY}" = "true" ]; then
387+
if [ "${USE_MOBY}" = "true" ] && ([ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ]); then
301388
# Install engine
302389
set +e # Handle error gracefully
303390
apt-get -y install --no-install-recommends moby-cli${cli_version_suffix} moby-buildx${buildx_version_suffix} moby-engine${engine_version_suffix}
304391
exit_code=$?
305392
set -e
306-
307-
if [ ${exit_code} -ne 0 ]; then
393+
394+
if [ ${exit_code} -ne 0 ]; then
308395
err "Packages for moby not available in OS ${ID} ${VERSION_CODENAME} (${architecture}). To resolve, either: (1) set feature option '\"moby\": false' , or (2) choose a compatible OS version (eg: 'ubuntu-20.04')."
309396
exit 1
310397
fi
311398

312399
# Install compose
313400
apt-get -y install --no-install-recommends moby-compose || err "Package moby-compose (Docker Compose v2) not available for OS ${ID} ${VERSION_CODENAME} (${architecture}). Skipping."
401+
elif [ "${USE_MOBY}" = "true" ] && ([ "$ID" = "fedora" ] || [ "$ID_LIKE" = "rhel" ]); then
402+
install_docker_or_moby
403+
404+
314405
else
315406
apt-get -y install --no-install-recommends docker-ce-cli${cli_version_suffix} docker-ce${engine_version_suffix}
316407
# Install compose
317408
apt-mark hold docker-ce docker-ce-cli
318409
apt-get -y install --no-install-recommends docker-compose-plugin || echo "(*) Package docker-compose-plugin (Docker Compose v2) not available for OS ${ID} ${VERSION_CODENAME} (${architecture}). Skipping."
319410
fi
320-
fi
411+
321412

322413
echo "Finished installing docker / moby!"
414+
fi
323415

324416
docker_home="/usr/libexec/docker"
325417
cli_plugins_dir="${docker_home}/cli-plugins"
@@ -369,11 +461,11 @@ if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then
369461
pip3 install --disable-pip-version-check --no-cache-dir --user "Cython<3.0" pyyaml wheel docker-compose --no-build-isolation
370462
fi
371463
else
372-
compose_version=${DOCKER_DASH_COMPOSE_VERSION#v}
464+
compose_version="2.34.0"
373465
docker_compose_url="https://github.com/docker/compose"
374466
find_version_from_git_tags compose_version "$docker_compose_url" "tags/v"
375467
echo "(*) Installing docker-compose ${compose_version}..."
376-
curl -fsSL "https://github.com/docker/compose/releases/download/v${compose_version}/docker-compose-linux-${target_compose_arch}" -o ${docker_compose_path} || {
468+
curl -fsSL "https://github.com/docker/compose/releases/download/2.34.0/docker-compose-linux-${target_compose_arch}" -o ${docker_compose_path} || {
377469
echo -e "\n(!) Failed to fetch the latest artifacts for docker-compose v${compose_version}..."
378470
fallback_compose "$docker_compose_url"
379471
}
@@ -404,7 +496,7 @@ fallback_compose-switch() {
404496
if [ "${INSTALL_DOCKER_COMPOSE_SWITCH}" = "true" ] && ! type compose-switch > /dev/null 2>&1; then
405497
if type docker-compose > /dev/null 2>&1; then
406498
echo "(*) Installing compose-switch..."
407-
current_compose_path="$(which docker-compose)"
499+
current_compose_path="$(command -v docker-compose)"
408500
target_compose_path="$(dirname "${current_compose_path}")/docker-compose-v1"
409501
compose_switch_version="latest"
410502
compose_switch_url="https://github.com/docker/compose-switch"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Function to check iptables version
9+
iptablesCheck() {
10+
if command -v iptables > /dev/null 2>&1; then
11+
if iptables --version > /dev/null 2>&1; then
12+
echo "✔️ iptables is installed and functional."
13+
else
14+
echo "❌ iptables is installed but not functional."
15+
fi
16+
else
17+
echo "❌ iptables command not found."
18+
fi
19+
}
20+
21+
# Function to check Fedora kernel version
22+
kernelVersionCheck() {
23+
if uname -r > /dev/null 2>&1; then
24+
echo "✔️ Kernel version: $(uname -r)"
25+
else
26+
echo "❌ Unable to retrieve kernel version."
27+
fi
28+
}
29+
30+
# Run checks
31+
check "iptables version" iptablesCheck
32+
check "kernel version" kernelVersionCheck
33+
34+
# Report results
35+
reportResults

test/docker-in-docker/scenarios.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,16 @@
166166
},
167167
"remoteUser": "vscode",
168168
"onCreateCommand": "docker ps && sleep 5s && docker ps"
169+
},
170+
"fedora_kernel": {
171+
"image": "fedora:41",
172+
"features": {
173+
"docker-in-docker": {
174+
"iptables": "true",
175+
"moby": "true",
176+
"installDockerBuildx": true,
177+
"dockerDashComposeVersion": "latest"
178+
}
179+
}
169180
}
170181
}

0 commit comments

Comments
 (0)