Skip to content

Commit d48e55d

Browse files
committed
docker: Fix $DOCKER_USER
Now we cp instead of mv $HOME as mv will fail due to the user not existing. We also only try to convert if the user hasn't been changed. Finally I added usage to the docker docs in install.md Closes #2056
1 parent ceceef1 commit d48e55d

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

ci/release-image/entrypoint.sh

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
#!/usr/bin/env sh
1+
#!/bin/sh
22
set -eu
33

4-
if [ "${DOCKER_USER-}" ]; then
4+
# This isn't set by default.
5+
export USER="$(whoami)"
6+
7+
if [ "${DOCKER_USER-}" != "$USER" ]; then
58
echo "$DOCKER_USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/nopasswd > /dev/null
69
sudo usermod --login "$DOCKER_USER" \
7-
--move-home --home "/home/$DOCKER_USER" \
10+
--home "/home/$DOCKER_USER" \
811
coder
912
sudo groupmod -n "$DOCKER_USER" coder
1013

14+
# We cannot use usermod to do this as it uses mv which will
15+
# fail as files are open in $HOME. We have to copy.
16+
sudo cp -a "$HOME" "/home/$DOCKER_USER"
17+
export HOME="/home/$DOCKER_USER"
18+
export USER="$(whoami)"
19+
1120
sudo sed -i "/coder/d" /etc/sudoers.d/nopasswd
1221
sudo sed -i "s/coder/$DOCKER_USER/g" /etc/fixuid/config.yml
13-
export HOME="/home/$DOCKER_USER"
1422
fi
1523

16-
# This isn't set by default.
17-
export USER="$(whoami)"
1824
dumb-init fixuid -q /usr/bin/code-server "$@"

doc/install.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,11 @@ code-server
179179
# easily access/modify your code-server config in $HOME/.config/code-server/config.json
180180
# outside the container.
181181
mkdir -p ~/.config
182-
docker run -it -p 127.0.0.1:8080:8080 \
182+
docker run -it --name code-server -p 127.0.0.1:8080:8080 \
183183
-v "$HOME/.config:/home/coder/.config" \
184184
-v "$PWD:/home/coder/project" \
185185
-u "$(id -u):$(id -g)" \
186+
-e "DOCKER_USER=$USER" \
186187
codercom/code-server:latest
187188
```
188189

0 commit comments

Comments
 (0)