Tweak non-root user logic
This commit is contained in:
@@ -8,11 +8,11 @@ FROM node:10
|
||||
# Avoid warnings by switching to noninteractive
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# The node image comes with a base non-root 'node' user, so the alternate
|
||||
# user here is primarily for Linux scenarios where you need to match your local
|
||||
# user UID/GID. See https://aka.ms/vscode-remote/containers/non-root-user.
|
||||
ARG USERNAME=vscode
|
||||
ARG USER_UID=1001
|
||||
# The node image comes with a base non-root 'node' user which this Dockerfile
|
||||
# gives sudo access. Hoewver, for Linux, this user's GID/UID must match your local
|
||||
# user UID/GID to avoid permission issues with bind mounts. Update USER_UID / USER_GID
|
||||
# if yours is not 1000. See https://aka.ms/vscode-remote/containers/non-root-user.
|
||||
ARG USER_UID=1000
|
||||
ARG USER_GID=$USER_UID
|
||||
|
||||
# Configure apt and install packages
|
||||
@@ -37,13 +37,12 @@ RUN apt-get update \
|
||||
&& npm install -g eslint \
|
||||
#
|
||||
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
|
||||
&& if [ "$USER_GID" != "1000" ]; then groupadd --gid $USER_GID $USERNAME; fi \
|
||||
&& if [ "$USER_UID" != "1000" ]; then useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME; fi \
|
||||
&& if [ "$USER_GID" != "1000" ]; then groupmod node --gid $USER_GID; fi \
|
||||
&& if [ "$USER_UID" != "1000" ]; then usermod --uid $USER_UID node; fi \
|
||||
# [Optional] Add sudo support for non-root users
|
||||
&& apt-get install -y sudo \
|
||||
&& if [ "$USER_UID" != "1000" ]; then echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME; fi \
|
||||
&& echo node ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/node \
|
||||
&& chmod 0440 /etc/sudoers.d/$USERNAME \
|
||||
&& chmod 0440 /etc/sudoers.d/node \
|
||||
#
|
||||
# Clean up
|
||||
&& apt-get autoremove -y \
|
||||
|
||||
Reference in New Issue
Block a user