Skip to content

Commit 32c5443

Browse files
rootnojaf
root
authored andcommitted
Try and create user instead of root.
1 parent e6e73f7 commit 32c5443

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
]
1616
}
1717
},
18-
"postCreateCommand": ".devcontainer/postCreate.sh"
18+
"postCreateCommand": ".devcontainer/postCreate.sh",
19+
"remoteUser": "devuser"
1920
}

docker/Dockerfile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,28 @@ FROM rust:1.80.1-bullseye
22
LABEL org.opencontainers.image.authors="Christoph Knittel <ck@cca.io>"
33
LABEL org.opencontainers.image.description="Docker image for ReScript development."
44

5-
RUN apt update && apt install -y --no-install-recommends ca-certificates curl git rsync opam musl-tools python3 python-is-python3
5+
RUN apt update && apt install -y --no-install-recommends sudo ca-certificates curl git rsync opam musl-tools python3 python-is-python3
66

77
# Node.js
88
RUN curl -sL https://deb.nodesource.com/setup_20.x | bash -
99
RUN apt install -y nodejs
1010

11+
# Create a non-root user and switch to it
12+
ARG USERNAME=devuser
13+
ARG USER_UID=1000
14+
ARG USER_GID=$USER_UID
15+
16+
RUN groupadd --gid $USER_GID $USERNAME \
17+
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
18+
&& usermod -aG sudo $USERNAME \
19+
&& mkdir /workspaces \
20+
&& chown -R $USERNAME:$USERNAME /workspaces
21+
22+
# Allow the devuser to use sudo without a password
23+
RUN echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
24+
25+
USER $USERNAME
26+
1127
# OCaml
1228
RUN opam init -y --bare --disable-sandboxing git+https://github.com/rescript-lang/opam-repository
1329
RUN opam switch create 5.2.0 --packages ocaml-option-static

0 commit comments

Comments
 (0)