Skip to content

Commit 570a1ff

Browse files
authored
fix: Improve docker example first user experience (coder#4972)
The base ubuntu image lands the user as root, but the terraform tempalte expected /home/coder to be used. This change adds a user with the same name as the Coder users username and allows them to sudo.
1 parent 4885ecc commit 570a1ff

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
FROM ubuntu
22

3-
RUN apt-get update && apt-get install -y curl wget git vim golang
3+
RUN apt-get update \
4+
&& apt-get install -y \
5+
curl \
6+
git \
7+
golang \
8+
sudo \
9+
vim \
10+
wget \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
ARG USER=coder
14+
RUN useradd --groups sudo --no-create-home ${USER} \
15+
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/${USER} \
16+
&& chmod 0440 /etc/sudoers.d/${USER}
17+
USER ${USER}
18+
WORKDIR /home/${USER}

examples/templates/docker/main.tf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ terraform {
1111
}
1212
}
1313

14+
locals {
15+
username = data.coder_workspace.me.owner
16+
}
17+
1418
data "coder_provisioner" "me" {
1519
}
1620

@@ -46,7 +50,7 @@ resource "coder_app" "code-server" {
4650
agent_id = coder_agent.main.id
4751
slug = "code-server"
4852
display_name = "code-server"
49-
url = "http://localhost:13337/?folder=/home/coder"
53+
url = "http://localhost:13337/?folder=/home/${local.username}"
5054
icon = "/icon/code.svg"
5155
subdomain = false
5256
share = "owner"
@@ -91,6 +95,9 @@ resource "docker_image" "main" {
9195
name = "coder-${data.coder_workspace.me.id}"
9296
build {
9397
path = "./build"
98+
build_arg = {
99+
USER = local.username
100+
}
94101
}
95102
triggers = {
96103
dir_sha1 = sha1(join("", [for f in fileset(path.module, "build/*") : filesha1(f)]))
@@ -112,7 +119,7 @@ resource "docker_container" "workspace" {
112119
ip = "host-gateway"
113120
}
114121
volumes {
115-
container_path = "/home/coder/"
122+
container_path = "/home/${local.username}"
116123
volume_name = docker_volume.home_volume.name
117124
read_only = false
118125
}

0 commit comments

Comments
 (0)