|
| 1 | +# Podman-in-Podman for Dev Containers |
| 2 | +# Allows running containers inside a dev container using Podman |
| 3 | + |
| 4 | +# [Choice] Podman version tag: latest or any version (e.g., v5.7.1, v5.7, v5, 5.7.1) |
| 5 | +# Version tags use 'v' prefix (e.g., v5.7.1, v5.7, v5) |
| 6 | +# The 'v' prefix is optional in input - if you specify '5.7.1', it will be used as 'v5.7.1' |
| 7 | +# For best results, specify the full tag with 'v' prefix (e.g., 'v5.7.1', 'v5.7', 'v5') |
| 8 | +ARG VARIANT=latest |
| 9 | +ARG PODMAN_TAG |
| 10 | +ARG INSTALL_BUILDAH="true" |
| 11 | +ARG INSTALL_SKOPEO="true" |
| 12 | + |
| 13 | +# Official Podman images from quay.io |
| 14 | +# Tag format: quay.io/podman/stable:latest or quay.io/podman/stable:v5.7.1, v5.7, v5, etc. |
| 15 | +# PODMAN_TAG is calculated and passed from devcontainer.json: |
| 16 | +# - 'latest' -> 'latest' |
| 17 | +# - Other versions -> add 'v' prefix if not present (e.g., '5.7.1' -> 'v5.7.1', 'v5.7.1' -> 'v5.7.1') |
| 18 | +# Default to 'latest' if PODMAN_TAG is not provided |
| 19 | +FROM quay.io/podman/stable:${PODMAN_TAG:-latest} |
| 20 | + |
| 21 | +# For official Podman images, Podman is already installed |
| 22 | +# Install additional tools and optional components |
| 23 | +RUN dnf install -y \ |
| 24 | + shadow-utils \ |
| 25 | + sudo \ |
| 26 | + curl \ |
| 27 | + wget \ |
| 28 | + ca-certificates \ |
| 29 | + findutils \ |
| 30 | + which \ |
| 31 | + tar \ |
| 32 | + gzip \ |
| 33 | + unzip \ |
| 34 | + procps-ng \ |
| 35 | + glibc-langpack-en \ |
| 36 | + podman-docker \ |
| 37 | + && dnf clean all |
| 38 | + |
| 39 | +# Install optional tools based on build arguments |
| 40 | +# Note: ARG must be redeclared after FROM to be available in this stage |
| 41 | +ARG INSTALL_BUILDAH |
| 42 | +ARG INSTALL_SKOPEO |
| 43 | +RUN if [ "${INSTALL_BUILDAH}" = "true" ]; then \ |
| 44 | + dnf install -y buildah && dnf clean all; \ |
| 45 | + fi \ |
| 46 | + && if [ "${INSTALL_SKOPEO}" = "true" ]; then \ |
| 47 | + dnf install -y skopeo && dnf clean all; \ |
| 48 | + fi |
| 49 | + |
| 50 | +# Configure subuid/subgid for rootless containers (will be set up by common-utils feature) |
| 51 | +# Using UID/GID 1001 to avoid conflicts with existing users in official Podman image |
| 52 | +RUN echo "vscode:100000:65536" >> /etc/subuid \ |
| 53 | + && echo "vscode:100000:65536" >> /etc/subgid \ |
| 54 | + && echo "1001:100000:65536" >> /etc/subuid \ |
| 55 | + && echo "1001:100000:65536" >> /etc/subgid |
| 56 | + |
| 57 | +# Configure Podman for nested container operation |
| 58 | +RUN mkdir -p /etc/containers \ |
| 59 | + && echo '[containers]' > /etc/containers/containers.conf \ |
| 60 | + && echo 'netns="host"' >> /etc/containers/containers.conf \ |
| 61 | + && echo 'userns="host"' >> /etc/containers/containers.conf \ |
| 62 | + && echo 'ipcns="host"' >> /etc/containers/containers.conf \ |
| 63 | + && echo 'utsns="host"' >> /etc/containers/containers.conf \ |
| 64 | + && echo 'cgroupns="host"' >> /etc/containers/containers.conf \ |
| 65 | + && echo 'log_driver = "k8s-file"' >> /etc/containers/containers.conf \ |
| 66 | + && echo '' >> /etc/containers/containers.conf \ |
| 67 | + && echo '[engine]' >> /etc/containers/containers.conf \ |
| 68 | + && echo 'cgroup_manager = "cgroupfs"' >> /etc/containers/containers.conf \ |
| 69 | + && echo 'events_logger = "file"' >> /etc/containers/containers.conf |
| 70 | + |
| 71 | +# Configure storage |
| 72 | +RUN echo '[storage]' > /etc/containers/storage.conf \ |
| 73 | + && echo 'driver = "overlay"' >> /etc/containers/storage.conf \ |
| 74 | + && echo '' >> /etc/containers/storage.conf \ |
| 75 | + && echo '[storage.options.overlay]' >> /etc/containers/storage.conf \ |
| 76 | + && echo 'mount_program = "/usr/bin/fuse-overlayfs"' >> /etc/containers/storage.conf |
| 77 | + |
| 78 | +# Set locale to avoid warnings |
| 79 | +ENV LANG=en_US.UTF-8 \ |
| 80 | + LC_ALL=en_US.UTF-8 |
| 81 | + |
| 82 | +# Create /etc/machine-id if it doesn't exist (required by some tools) |
| 83 | +# This is a dummy machine-id for container environments (32 hex chars, no hyphens per systemd spec) |
| 84 | +RUN if [ ! -f /etc/machine-id ]; then \ |
| 85 | + if [ -f /proc/sys/kernel/random/uuid ]; then \ |
| 86 | + # Convert UUID format to 32-char hex string (remove hyphens) \ |
| 87 | + cat /proc/sys/kernel/random/uuid | tr -d '-' > /etc/machine-id; \ |
| 88 | + elif command -v dbus-uuidgen >/dev/null 2>&1; then \ |
| 89 | + dbus-uuidgen | tr -d '-' > /etc/machine-id; \ |
| 90 | + else \ |
| 91 | + # Fallback: generate 32 hex characters \ |
| 92 | + od -An -N16 -tx1 /dev/urandom | tr -d ' \n' > /etc/machine-id || \ |
| 93 | + echo "00000000000000000000000000000000" > /etc/machine-id; \ |
| 94 | + fi; \ |
| 95 | + fi |
| 96 | + |
| 97 | +# Note: The common-utils feature will create the vscode user |
0 commit comments