-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(template_ws): Simplify user creation; Reorder commands for b…
…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
Showing
1 changed file
with
21 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |