Open4
ROS2 Humble GUIなし Docker Base (Single-Arch amd64 or Multi-Arch amd64/arm64)
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
ARG USERNAME=user
ARG ROS2_WS=/home/${USERNAME}/ros2_ws
ARG DISTRO=humble
SHELL ["/bin/bash", "-c"]
# Install ROS2 Humble
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y locales \
&& locale-gen en_US en_US.UTF-8 \
&& update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 \
&& export LANG=en_US.UTF-8 \
&& apt-get install -y --no-install-recommends \
curl \
wget \
gcc \
git \
make \
bash-completion \
gnupg2 \
lsb-release \
build-essential \
ca-certificates \
&& curl \
-sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key \
-o /usr/share/keyrings/ros-archive-keyring.gpg \
&& echo "\
deb [arch=$(dpkg --print-architecture) \
signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] \
http://packages.ros.org/ros2/ubuntu \
$(lsb_release -cs) main" \
| tee /etc/apt/sources.list.d/ros2.list > /dev/null \
&& apt-get install -y \
software-properties-common \
&& add-apt-repository universe \
&& apt-get install -y --no-install-recommends \
software-properties-common \
python-is-python3 \
python3-pip \
python3-rosdep \
python3-argcomplete \
python3-colcon-common-extensions \
ros-${DISTRO}-ros-base \
ros-dev-tools \
&& apt clean \
&& rm -rf /var/lib/apt/lists/* \
&& rm /etc/apt/apt.conf.d/docker-clean
# ROS2 environment setting
RUN echo "root:root" | chpasswd \
&& useradd \
--create-home \
--home-dir /home/${USERNAME} \
--shell /bin/bash \
--user-group \
--groups adm,sudo \
${USERNAME} \
&& echo "${USERNAME}:${USERNAME}" | chpasswd \
&& cat /dev/null > /etc/sudoers.d/${USERNAME} \
&& echo "%${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> \
/etc/sudoers.d/${USERNAME} \
&& mkdir -p ${ROS2_WS} \
&& chown ${USERNAME}:${USERNAME} ${ROS2_WS}
USER ${USERNAME}
WORKDIR ${ROS2_WS}
RUN echo "source /opt/ros/${DISTRO}/setup.bash" >> ~/.bashrc \
&& echo -e "\n\
ID=2\n\
if [ \$ID -eq 0 ]; then\n\
export ROS_LOCALHOST_ONLY=1\n\
else\n\
export ROS_DOMAIN_ID=\$ID\n\
fi\n" >> ~/.bashrc \
&& echo "sudo rosdep init" >> ~/.bashrc \
&& echo "sudo rosdep fix-permissions" >> ~/.bashrc \
&& echo "rosdep update" >> ~/.bashrc
TAG=20230125
- Single-Arch (Local)
docker build \ --no-cache \ --build-arg USERNAME=user \ -t pinto0309/ros2-humble-base:${TAG} .
or
- Multi-Arch (Docker Hub)
docker buildx create --name multiarch-builder docker buildx use multiarch-builder docker buildx build \ --no-cache \ --platform linux/amd64,linux/arm64 \ --build-arg USERNAME=user \ -t pinto0309/ros2-humble-base:${TAG} \ --push .
docker buildx imagetools inspect pinto0309/ros2-humble-base:${TAG}
docker run --rm -it \
-v `pwd`:/home/user/ros2_ws \
-w /home/user/ros2_ws \
pinto0309/ros2-humble-base:${TAG}
初回起動後に ~/.bashrc
の以下3行を削除してコンテナをコミットすると良さげ。
sudo rosdep init
sudo rosdep fix-permissions
rosdep update