|
| 1 | +ARG UBUNTU_VERSION=noble |
| 2 | +FROM ubuntu:${UBUNTU_VERSION} |
| 3 | + |
| 4 | +SHELL ["/bin/bash", "-c"] |
| 5 | +ENV DEBIAN_FRONTEND=noninteractive |
| 6 | + |
| 7 | +# Base certs + gnupg so we can add the Docker apt repo |
| 8 | +RUN apt-get update && \ |
| 9 | + apt-get upgrade -y --no-install-recommends --no-install-suggests && \ |
| 10 | + apt-get install -y --no-install-recommends --no-install-suggests \ |
| 11 | + ca-certificates curl gnupg lsb-release && \ |
| 12 | + rm -rf /var/lib/apt/lists/* |
| 13 | + |
| 14 | +# Docker official apt repo (Debian/Ubuntu) |
| 15 | +RUN install -m 0755 -d /etc/apt/keyrings && \ |
| 16 | + curl -fsSL https://download.docker.com/linux/ubuntu/gpg \ |
| 17 | + | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \ |
| 18 | + chmod a+r /etc/apt/keyrings/docker.gpg && \ |
| 19 | + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable" \ |
| 20 | + > /etc/apt/sources.list.d/docker.list |
| 21 | + |
| 22 | +# Baseline packages + Docker engine |
| 23 | +RUN apt-get update && \ |
| 24 | + apt-get install -y --no-install-recommends --no-install-suggests \ |
| 25 | + bash \ |
| 26 | + build-essential \ |
| 27 | + containerd.io \ |
| 28 | + docker-ce \ |
| 29 | + docker-ce-cli \ |
| 30 | + docker-buildx-plugin \ |
| 31 | + docker-compose-plugin \ |
| 32 | + git \ |
| 33 | + htop \ |
| 34 | + iproute2 \ |
| 35 | + jq \ |
| 36 | + openssh-client \ |
| 37 | + less \ |
| 38 | + locales \ |
| 39 | + man \ |
| 40 | + pipx \ |
| 41 | + python3 \ |
| 42 | + python3-pip \ |
| 43 | + rsync \ |
| 44 | + software-properties-common \ |
| 45 | + sudo \ |
| 46 | + systemd \ |
| 47 | + systemd-sysv \ |
| 48 | + unzip \ |
| 49 | + vim \ |
| 50 | + wget && \ |
| 51 | + rm -rf /var/lib/apt/lists/* |
| 52 | + |
| 53 | +# Node.js LTS via NodeSource (needed by code-server, devcontainers/cli, etc.) |
| 54 | +RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \ |
| 55 | + apt-get install -y --no-install-recommends nodejs && \ |
| 56 | + rm -rf /var/lib/apt/lists/* |
| 57 | + |
| 58 | +# Pre-install @devcontainers/cli globally so the Coder module doesn't need |
| 59 | +# to (which fails for non-root users installing to /usr/lib/node_modules). |
| 60 | +RUN npm install -g @devcontainers/cli |
| 61 | + |
| 62 | +# Pre-populate system known_hosts for common git forges so SSH clones don't |
| 63 | +# race the agent's ssh-keyscan startup step. |
| 64 | +RUN ssh-keyscan -t rsa,ecdsa,ed25519 github.com gitlab.com bitbucket.org \ |
| 65 | + >> /etc/ssh/ssh_known_hosts 2>/dev/null |
| 66 | + |
| 67 | +# Disable containerd-snapshotter so image/layer data stays under |
| 68 | +# /var/lib/docker (classic overlay2) instead of /var/lib/containerd. The |
| 69 | +# persistent devcontainer cache volume only covers /var/lib/docker. |
| 70 | +RUN mkdir -p /etc/docker && \ |
| 71 | + printf '{\n "features": { "containerd-snapshotter": false }\n}\n' > /etc/docker/daemon.json |
| 72 | + |
| 73 | +# Enable Docker under systemd |
| 74 | +RUN systemctl enable docker |
| 75 | + |
| 76 | +# Standalone docker-compose symlink (optional convenience) |
| 77 | +RUN ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/bin/docker-compose |
| 78 | + |
| 79 | +# UTF-8 locale |
| 80 | +RUN locale-gen en_US.UTF-8 |
| 81 | +ENV LANG=en_US.UTF-8 |
| 82 | +ENV LANGUAGE=en_US.UTF-8 |
| 83 | +ENV LC_ALL=en_US.UTF-8 |
| 84 | + |
| 85 | +# Replace default 'ubuntu' user with 'coder' at uid 1000, in docker group, passwordless sudo |
| 86 | +RUN userdel -r ubuntu 2>/dev/null || true && \ |
| 87 | + useradd coder \ |
| 88 | + --create-home \ |
| 89 | + --shell=/bin/bash \ |
| 90 | + --groups=docker \ |
| 91 | + --uid=1000 \ |
| 92 | + --user-group && \ |
| 93 | + echo "coder ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/nopasswd && \ |
| 94 | + chmod 0440 /etc/sudoers.d/nopasswd |
| 95 | + |
| 96 | +USER coder |
| 97 | +RUN pipx ensurepath |
| 98 | + |
| 99 | +USER root |
| 100 | + |
| 101 | +# Coder agent: systemd unit runs /etc/coder/agent-init.sh as the coder user |
| 102 | +# after dockerd is up. The script itself is uploaded at container-create time |
| 103 | +# by the Terraform template (kreuzwerker/docker `upload` block). |
| 104 | +RUN mkdir -p /etc/coder && \ |
| 105 | + cat > /etc/systemd/system/coder-agent.service <<'EOF' |
| 106 | +[Unit] |
| 107 | +Description=Coder Agent |
| 108 | +After=docker.service network-online.target |
| 109 | +Wants=network-online.target docker.service |
| 110 | +ConditionPathExists=/etc/coder/agent-init.sh |
| 111 | + |
| 112 | +[Service] |
| 113 | +Type=simple |
| 114 | +User=coder |
| 115 | +Group=coder |
| 116 | +WorkingDirectory=/home/coder |
| 117 | +PassEnvironment=CODER_AGENT_TOKEN |
| 118 | +ExecStart=/bin/bash /etc/coder/agent-init.sh |
| 119 | +Restart=on-failure |
| 120 | +RestartSec=5 |
| 121 | + |
| 122 | +[Install] |
| 123 | +WantedBy=multi-user.target |
| 124 | +EOF |
| 125 | +RUN systemctl enable coder-agent.service |
| 126 | + |
| 127 | +CMD ["/sbin/init"] |
0 commit comments