Code-server: Ability to change username inside the docker container?

Created on 1 Aug 2019  路  10Comments  路  Source: cdr/code-server

Hi. it would be nice to be able to pass in the username and uid|gid as environmental variables when launching container.

So we dont have to use a name coder and use something specific to the user.

question

Most helpful comment

Let's add a environment variable to configure it!

All 10 comments

You could replace the entrypoint in your image with a script that changes the username to something stored in an env variable. Something like the following should work (untested):

#!/bin/sh
usermod -l coder $CODER_USER
/usr/bin/dumb-init /usr/local/bin/code-server

This won't change the home directory from /home/coder to /home/deansheather though.

@loganto @deansheather It's a bit late but here's the script I'm using (allows configuring VS_UID, VS_GID, and VS_USERNAME):

!/usr/bin/dumb-init /bin/sh
groupadd --gid ${VS_GID:-1000} $VS_USERNAME
adduser --uid ${VS_UID:-1000} --gid ${VS_GID:-1000} --home /home/${VS_USERNAME:-coder} --gecos '' --disabled-password ${VS_USERNAME:-coder}
echo "${VS_USERNAME:-coder} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd
cd /home/${VS_USERNAME:-coder}
runuser --login ${VS_USERNAME:-coder} --session-command="PASSWORD=$PASSWORD code-server --disable-telemetry --host 0.0.0.0 $@"

This really should be baked in by default.

Not sure why you need all that, just use:

sudo usermod -l nhooyr coder
sudo usermod -d /home/nhooyr -m nhooyr

For example to set it the username to nhooyr.

And you can already adjust the uid/gid you run the image as and the image will automatically change the coder user to reflect that uid/gid.

You have a good point, but I would like this to be merged into the code-server upstream image. My script was a quick hack just to get things working.

Let's add a environment variable to configure it!

@nhooyr Any progress on this? Or am I expected to submit a PR...?

I'll take care of it soon.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

broady picture broady  路  3Comments

lshamis picture lshamis  路  3Comments

pchecinski picture pchecinski  路  3Comments

pchecinski picture pchecinski  路  3Comments

chrischabot picture chrischabot  路  3Comments