-
Notifications
You must be signed in to change notification settings - Fork 591
Docker-in-docker feature support for fedora #1328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
2b69559
ff70473
717c624
49b3432
1ff2a8e
c69dcf9
2f769b9
e5984a9
6ddceb8
d62851f
5e5b3eb
69dd8bd
b224b67
3378558
3d5d00b
88ef5bf
a86c997
98a73fe
6c2ca34
6a61aeb
a3ed786
2958fdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,19 +62,39 @@ fi | |
|
|
||
| apt_get_update() | ||
| { | ||
| if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then | ||
| . /etc/os-release | ||
| if [ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ]; then | ||
| if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then | ||
| echo "Running apt-get update..." | ||
| apt-get update -y | ||
| fi | ||
| fi | ||
| } | ||
|
|
||
| # Checks if packages are installed and installs them if not | ||
| check_packages() { | ||
|
|
||
| if [ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ] || [ "$ID_LIKE" = "debian" ]; then | ||
| if ! dpkg -s "$@" > /dev/null 2>&1; then | ||
| apt_get_update | ||
| apt-get -y install --no-install-recommends "$@" | ||
| apt-get install -y gnupg curl | ||
| fi | ||
| elif [ "$ID" = "fedora" ] || [ "$ID" = "centos" ] || [ "$ID_LIKE" == "rhel" ]; then | ||
| if ! dnf list installed "$@" > /dev/null 2>&1; then | ||
| dnf -y install "$@" | ||
| fi | ||
| fi | ||
|
|
||
| } | ||
| # Install dependencies for both fedora and ubuntu | ||
| missing=0; for cmd in git wget which; do command -v $cmd &>/dev/null || { echo "$cmd not found"; missing=1; }; done; \ | ||
| if [ $missing -eq 1 ]; then \ | ||
| echo "Installing missing packages..."; \ | ||
| if command -v dnf &>/dev/null; then dnf install -y git wget which curl jq; \ | ||
| elif command -v apt &>/dev/null; then apt-get update && apt-get install -y git wget curl jq; \ | ||
| else echo "Unsupported package manager"; exit 1; fi; \ | ||
| fi | ||
|
|
||
| # Figure out correct version of a three part version number is not passed | ||
| find_version_from_git_tags() { | ||
|
|
@@ -191,8 +211,21 @@ export DEBIAN_FRONTEND=noninteractive | |
|
|
||
| # Source /etc/os-release to get OS info | ||
| . /etc/os-release | ||
| # Fetch host/container arch. | ||
| architecture="$(dpkg --print-architecture)" | ||
| # Fetch host/container architecture | ||
| if [ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ]; then | ||
| architecture="$(dpkg --print-architecture)" | ||
| elif [ "$ID" = "fedora" ] || [ "$ID_LIKE" = "rhel" ]; then | ||
| architecture="$(uname -m)" | ||
| case "$architecture" in | ||
| x86_64) architecture="amd64" ;; | ||
| aarch64) architecture="arm64" ;; | ||
| *) echo "Unsupported architecture: $architecture"; exit 1 ;; | ||
| esac | ||
| else | ||
| echo "Unsupported operating system: $ID" | ||
| exit 1 | ||
| fi | ||
|
|
||
|
|
||
| # Check if distro is supported | ||
| if [ "${USE_MOBY}" = "true" ]; then | ||
|
|
@@ -217,37 +250,38 @@ if ! type git > /dev/null 2>&1; then | |
| check_packages git | ||
| fi | ||
|
|
||
|
|
||
|
|
||
| # Swap to legacy iptables for compatibility | ||
| if type iptables-legacy > /dev/null 2>&1; then | ||
| update-alternatives --set iptables /usr/sbin/iptables-legacy | ||
| update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy | ||
| fi | ||
|
|
||
|
|
||
|
|
||
| # Set up the necessary apt repos (either Microsoft's or Docker's) | ||
| if [ "${USE_MOBY}" = "true" ]; then | ||
| if [ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ]; then | ||
| if [ "${USE_MOBY}" = "true" ]; then | ||
|
|
||
| # Name of open source engine/cli | ||
| engine_package_name="moby-engine" | ||
| cli_package_name="moby-cli" | ||
|
|
||
| # Name of open source engine/cli | ||
| engine_package_name="moby-engine" | ||
| cli_package_name="moby-cli" | ||
| # Import key safely and import Microsoft apt repo | ||
| curl -sSL ${MICROSOFT_GPG_KEYS_URI} | gpg --dearmor > /usr/share/keyrings/microsoft-archive-keyring.gpg | ||
| echo "deb [arch=${architecture} signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/repos/microsoft-${ID}-${VERSION_CODENAME}-prod ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/microsoft.list | ||
| else | ||
| # Name of licensed engine/cli | ||
| engine_package_name="docker-ce" | ||
| cli_package_name="docker-ce-cli" | ||
|
|
||
| # Import key safely and import Microsoft apt repo | ||
| curl -sSL ${MICROSOFT_GPG_KEYS_URI} | gpg --dearmor > /usr/share/keyrings/microsoft-archive-keyring.gpg | ||
| echo "deb [arch=${architecture} signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/repos/microsoft-${ID}-${VERSION_CODENAME}-prod ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/microsoft.list | ||
| else | ||
| # Name of licensed engine/cli | ||
| engine_package_name="docker-ce" | ||
| cli_package_name="docker-ce-cli" | ||
| # Import key safely and import Docker apt repo | ||
| curl -fsSL https://download.docker.com/linux/${ID}/gpg | gpg --dearmor > /usr/share/keyrings/docker-archive-keyring.gpg | ||
| echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/${ID} ${VERSION_CODENAME} stable" > /etc/apt/sources.list.d/docker.list | ||
| fi | ||
|
|
||
| # Import key safely and import Docker apt repo | ||
| curl -fsSL https://download.docker.com/linux/${ID}/gpg | gpg --dearmor > /usr/share/keyrings/docker-archive-keyring.gpg | ||
| echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/${ID} ${VERSION_CODENAME} stable" > /etc/apt/sources.list.d/docker.list | ||
| # Refresh apt lists | ||
| apt-get update | ||
| fi | ||
|
|
||
| # Refresh apt lists | ||
| apt-get update | ||
|
|
||
| # Soft version matching | ||
| if [ "${DOCKER_VERSION}" = "latest" ] || [ "${DOCKER_VERSION}" = "lts" ] || [ "${DOCKER_VERSION}" = "stable" ]; then | ||
| # Empty, meaning grab whatever "latest" is in apt repo | ||
|
|
@@ -293,33 +327,93 @@ if [ "${USE_MOBY}" = "true" ]; then | |
| fi | ||
| fi | ||
|
|
||
| install_docker_or_moby() { | ||
| # Check for the OS type | ||
| if [ -f /etc/os-release ]; then | ||
| . /etc/os-release | ||
| fi | ||
|
|
||
| # Set Fedora version for repository URL | ||
| RELEASE_VER=$(sed 's/\..*//' /etc/fedora-release) | ||
|
|
||
| # Check if the user wants to use Moby (open-source version of Docker) | ||
| if [ "${USE_MOBY}" == "true" ]; then | ||
| echo "Setting up Moby repository for Fedora..." | ||
| # Add Moby repository (Microsoft) | ||
| echo "[microsoft]" > /etc/yum.repos.d/microsoft.repo | ||
| echo "name=Microsoft Packages" >> /etc/yum.repos.d/microsoft.repo | ||
| echo "baseurl=https://packages.microsoft.com/yumrepos/microsoft-fedora$RELEASE_VER" >> /etc/yum.repos.d/microsoft.repo | ||
| echo "enabled=1" >> /etc/yum.repos.d/microsoft.repo | ||
| echo "gpgcheck=1" >> /etc/yum.repos.d/microsoft.repo | ||
| echo "gpgkey=https://packages.microsoft.com/keys/microsoft.asc" >> /etc/yum.repos.d/microsoft.repo | ||
|
|
||
| # Install Moby Engine and CLI | ||
| echo "Installing Moby packages..." | ||
| sudo dnf install -y moby-engine moby-cli moby-buildx --skip-unavailable | ||
|
|
||
| else | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When does the code inside this |
||
| echo "Setting up Docker repository for Fedora..." | ||
| # Add Docker repository (Docker CE) | ||
| echo "[docker-ce-stable]" > /etc/yum.repos.d/docker.repo | ||
| echo "name=Docker CE Stable - Fedora $RELEASE_VER" >> /etc/yum.repos.d/docker.repo | ||
| echo "baseurl=https://download.docker.com/linux/fedora/$RELEASE_VER/stable/\$basearch" >> /etc/yum.repos.d/docker.repo | ||
| echo "enabled=1" >> /etc/yum.repos.d/docker.repo | ||
| echo "gpgcheck=1" >> /etc/yum.repos.d/docker.repo | ||
| echo "gpgkey=https://download.docker.com/linux/fedora/gpg" >> /etc/yum.repos.d/docker.repo | ||
|
|
||
| # Install Docker CE | ||
| echo "Installing Docker CE..." | ||
| dnf install -y docker-ce docker-ce-cli containerd.io | ||
| fi | ||
|
|
||
| # Enable and start Docker/Moby | ||
| echo "Enabling and starting Docker/Moby service..." | ||
| systemctl enable docker | ||
|
|
||
| # Add the current user to the docker group | ||
| echo "Adding user to Docker group..." | ||
| usermod -aG docker ${USERNAME} | ||
|
|
||
| # Clean up DNF cache | ||
| echo "Cleaning up DNF cache..." | ||
| dnf clean all | ||
|
|
||
| # Final message | ||
| echo "Docker/Moby installation completed successfully!" | ||
| echo "Please log out and log back in to apply group changes." | ||
| } | ||
| # Install Docker / Moby CLI if not already installed | ||
| if type docker > /dev/null 2>&1 && type dockerd > /dev/null 2>&1; then | ||
| echo "Docker / Moby CLI and Engine already installed." | ||
| else | ||
| if [ "${USE_MOBY}" = "true" ]; then | ||
| if [ "${USE_MOBY}" = "true" ] && ([ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ]); then | ||
| # Install engine | ||
| set +e # Handle error gracefully | ||
| apt-get -y install --no-install-recommends moby-cli${cli_version_suffix} moby-buildx${buildx_version_suffix} moby-engine${engine_version_suffix} | ||
| exit_code=$? | ||
| set -e | ||
| if [ ${exit_code} -ne 0 ]; then | ||
|
|
||
| if [ ${exit_code} -ne 0 ]; then | ||
| 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')." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Install compose | ||
| 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." | ||
| elif [ "${USE_MOBY}" = "true" ] && ([ "$ID" = "fedora" ] || [ "$ID_LIKE" = "rhel" ]); then | ||
| install_docker_or_moby | ||
|
|
||
|
|
||
| else | ||
| apt-get -y install --no-install-recommends docker-ce-cli${cli_version_suffix} docker-ce${engine_version_suffix} | ||
| # Install compose | ||
| apt-mark hold docker-ce docker-ce-cli | ||
| 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." | ||
| fi | ||
| fi | ||
|
|
||
|
|
||
| echo "Finished installing docker / moby!" | ||
| fi | ||
|
|
||
| docker_home="/usr/libexec/docker" | ||
| cli_plugins_dir="${docker_home}/cli-plugins" | ||
|
|
@@ -369,11 +463,11 @@ if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then | |
| pip3 install --disable-pip-version-check --no-cache-dir --user "Cython<3.0" pyyaml wheel docker-compose --no-build-isolation | ||
| fi | ||
| else | ||
| compose_version=${DOCKER_DASH_COMPOSE_VERSION#v} | ||
| compose_version="${DOCKER_DASH_COMPOSE_VERSION#v}" | ||
| docker_compose_url="https://github.com/docker/compose" | ||
| find_version_from_git_tags compose_version "$docker_compose_url" "tags/v" | ||
| echo "(*) Installing docker-compose ${compose_version}..." | ||
| curl -fsSL "https://github.com/docker/compose/releases/download/v${compose_version}/docker-compose-linux-${target_compose_arch}" -o ${docker_compose_path} || { | ||
| curl -fsSL "https://github.com/docker/compose/releases/download/compose_version/docker-compose-linux-${target_compose_arch}" -o ${docker_compose_path} || { | ||
| echo -e "\n(!) Failed to fetch the latest artifacts for docker-compose v${compose_version}..." | ||
| fallback_compose "$docker_compose_url" | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library | ||
| source dev-container-features-test-lib | ||
|
|
||
| # Function to check iptables version | ||
| iptablesCheck() { | ||
| if command -v iptables > /dev/null 2>&1; then | ||
| if iptables --version > /dev/null 2>&1; then | ||
| echo "✔️ iptables is installed and functional." | ||
| else | ||
| echo "❌ iptables is installed but not functional." | ||
| fi | ||
| else | ||
| echo "❌ iptables command not found." | ||
| fi | ||
| } | ||
|
|
||
| # Function to check Fedora kernel version | ||
| kernelVersionCheck() { | ||
| if uname -r > /dev/null 2>&1; then | ||
| echo "✔️ Kernel version: $(uname -r)" | ||
| else | ||
| echo "❌ Unable to retrieve kernel version." | ||
| fi | ||
| } | ||
|
|
||
| # Run checks | ||
| check "iptables version" iptablesCheck | ||
| check "kernel version" kernelVersionCheck | ||
|
|
||
| # Report results | ||
| reportResults |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,5 +166,16 @@ | |
| }, | ||
| "remoteUser": "vscode", | ||
| "onCreateCommand": "docker ps && sleep 5s && docker ps" | ||
| }, | ||
| "fedora_kernel": { | ||
| "image": "fedora:41", | ||
| "features": { | ||
| "docker-in-docker": { | ||
| "iptables": "true", | ||
| "moby": "true", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have another test case also with |
||
| "installDockerBuildx": true, | ||
| "dockerDashComposeVersion": "latest" | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please correct the indentation for better readability.