Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive
ARG USER
ARG UID
ARG GID
ARG USER_ID
ARG GROUP_ID

# Force apt "--no-install-recommends" to limit the image size
RUN echo 'APT::Install-Recommends "0";' >> /etc/apt/apt.conf.d/99local && \
Expand Down Expand Up @@ -79,7 +79,6 @@ ENV LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US.UTF-8

USER $USER

WORKDIR /home/$USER
USER "$USER"

WORKDIR "/home/$USER"
15 changes: 10 additions & 5 deletions create_user.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#!/bin/bash

# If not provided, defaults to "ubuntu" with UID and GID of 1000
USER=${USER:-"ubuntu"}
USER_ID=${USER_ID:-1000}
GROUP_ID=${GROUP_ID:-1000}

# Create user
groupadd -g $GID $USER
useradd -m -s /bin/bash -u $UID -g $GID $USER
groupadd -g "$GROUP_ID" "$USER"
useradd -m -s /bin/bash -u "$USER_ID" -g "$GROUP_ID" "$USER"

# Add the user to sudo group
apt-get update
apt-get -qq install sudo
usermod -aG sudo $USER
usermod -aG sudo "$USER"

# Add user to sudoers without password
echo "${USER} ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/$USER
chmod 0440 /etc/sudoers.d/$USER
echo "${USER} ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/"$USER"
chmod 0440 /etc/sudoers.d/"$USER"
Loading