-
Notifications
You must be signed in to change notification settings - Fork 44
/
create-user.dockerfile
50 lines (39 loc) · 1.4 KB
/
create-user.dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
FROM tverous/pytorch-notebook
ARG MY_UID
ARG MY_GID
ARG USER
ARG HOME
# for prompts
ENV RED='\033[0;31m'
ENV GREEN='\033[0;32m'
ENV NC='\033[0m'
# run id -u
ENV MY_UID=${MY_UID}
# run id -g
ENV MY_GID=${MY_GID}
# your username
ENV USER=${USER}
# your home directory
ENV HOME=${HOME}
RUN test ! -z ${MY_UID} && echo ${GREEN}"MY_UID is set to ${MY_UID}"${NC} || (echo ${RED}"MY_UID is not set"${NC} && exit 1)
RUN test ! -z ${MY_GID} && echo ${GREEN}"MY_GID is set to ${MY_GID}"${NC} || (echo ${RED}"MY_GID is not set"${NC} && exit 1)
RUN test ! -z ${USER} && echo ${GREEN}"USER is set to ${USER}"${NC} || (echo ${RED}"USER is not set"${NC} && exit 1)
RUN test ! -z ${HOME} && echo ${GREEN}"HOME is set to ${HOME}"${NC} || (echo ${RED}"HOME is not set"${NC} && exit 1)
RUN unset RED && unset GREEN && unset NC
# install sudo
RUN apt-get update && apt-get install -y \
sudo
# add a new user with the specific user id and group id
RUN groupadd -g ${MY_GID} ${USER} \
&& useradd ${USER} -u ${MY_UID} -g ${MY_GID} -d ${HOME} -m -s /bin/bash
# for user space executables
ENV PATH="${PATH}:${HOME}/.local/bin/"
# add user to the sudo group
RUN usermod -aG sudo ${USER}
# TODO: disable sudo password
RUN echo "%${USER} ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers && exit
USER ${USER}
WORKDIR ${HOME}
# start jupyter lab
CMD ["jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--allow-root", "--no-browser"]
EXPOSE 8888