Skip to content

Commit

Permalink
refactor(template_ws): Simplify user creation; Reorder commands for b…
Browse files Browse the repository at this point in the history
…etter caching

For example, common tools such as curl are seldomly changed, and could be executed before other dockerfile commands to save build time.
  • Loading branch information
j3soon committed Aug 20, 2024
1 parent 61cee56 commit 8abaeda
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions template_ws/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
# Base Image : https://hub.docker.com/r/osrf/ros/tags?page=1&name=humble
FROM osrf/ros:humble-desktop-full

# Arguments for the default user
ARG USERNAME=user
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
#
# [Optional] Add sudo support. Omit if you don't need to install software after connecting.
&& apt-get update \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME \
&& rm -rf /var/lib/apt/lists/*

# Upgrade packages
# Ref: https://pythonspeed.com/articles/security-updates-in-docker/
RUN apt-get update && apt-get upgrade -y \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y python3-pip \
&& rm -rf /var/lib/apt/lists/*
ENV SHELL /bin/bash

# ********************************************************
# * Anything else you want to do like clean up goes here *
# ********************************************************
# Install sudo and create a user with sudo privileges
# Ref: https://stackoverflow.com/a/65434659
RUN apt-get update && apt-get install -y sudo \
&& useradd -m -s /bin/bash -u $USER_UID -G sudo $USERNAME \
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
&& rm -rf /var/lib/apt/lists/*

# Install common tools
RUN apt-get update && apt-get install -y \
curl \
git \
git-extras \
htop \
net-tools \
tmux \
vim \
wget \
&& rm -rf /var/lib/apt/lists/*

# Install Python pip
RUN apt-get update && apt-get install -y python3-pip \
&& rm -rf /var/lib/apt/lists/*

# Install custom tools
RUN apt-get update && apt-get install -y \
git-extras \
&& rm -rf /var/lib/apt/lists/*

# Install ROS2 RVIZ and Gazebo
RUN apt-get update && apt-get install -y \
ros-$ROS_DISTRO-gazebo-ros-pkgs \
ros-$ROS_DISTRO-rviz2 \
&& rm -rf /var/lib/apt/lists/*

# TODO: Add more commands here

COPY .bashrc /home/$USERNAME/.bashrc

# [Optional] Set the default user. Omit if you want to keep the default as root.
USER $USERNAME
CMD ["/bin/bash"]

0 comments on commit 8abaeda

Please sign in to comment.