Skip to content

Commit

Permalink
fix dockerfile to set host UID, GID, time zone
Browse files Browse the repository at this point in the history
DCO 1.1 Signed-off-by: Tatsuya Ishihara <tisihara@jp.ibm.com>
  • Loading branch information
tatsuya-ishihara committed Dec 18, 2024
1 parent 65b3d1e commit 0b7514f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
3 changes: 3 additions & 0 deletions docker-compose-common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ services:
- XAUTHORITY=/tmp/.docker.xauth
- NVIDIA_DRIVER_CAPABILITIES=compute,graphics,utility,video,display
- NVIDIA_VISIBLE_DEVICES=all
- HOST_UID
- HOST_GID
- HOST_TZ
- ROS_LOG_DIR
- CABOT_ROSBAG_BACKEND
- CABOT_ROSBAG_COMPRESSION
Expand Down
8 changes: 3 additions & 5 deletions docker/bag/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ ARG ROS_DISTRO

RUN apt update && \
apt install -y --no-install-recommends \
gosu \
ros-$ROS_DISTRO-dwb-msgs \
ros-$ROS_DISTRO-rosbridge-msgs \
ros-$ROS_DISTRO-nav2-msgs \
Expand Down Expand Up @@ -151,17 +152,14 @@ COPY ros_entrypoint.sh /ros_entrypoint.sh
RUN sed -i 's:custom_ws:underlay_ws:' /ros_entrypoint.sh
RUN chmod +x /ros_entrypoint.sh

USER $USERNAME

ENV HOME /home/$USERNAME

WORKDIR $HOME/bag_ws

RUN mkdir -p $HOME/bag_ws/script
RUN chown -R $USERNAME:$USERNAME $HOME/bag_ws

COPY --chown=$USERNAME:$USERNAME --from=cabot_src ./cabot-navigation/docker/ros2/launch.sh /

COPY --from=build $HOME/bag_ws/install $HOME/bag_ws/install
COPY --chown=$USERNAME:$USERNAME --from=build $HOME/bag_ws/install $HOME/bag_ws/install
COPY --chown=$USERNAME:$USERNAME --from=cabot_src ./cabot-navigation/script /home/developer/bag_ws/script

CMD [ "/launch.sh record" ]
25 changes: 24 additions & 1 deletion docker/bag/ros_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,33 @@

set -e

# Default values
HOST_UID=${HOST_UID:-1000}
HOST_GID=${HOST_GID:-1000}
HOST_TZ=${HOST_TZ:-UTC}

if [[ $TZ != $HOST_TZ ]]; then
# Setting up timezone
sudo ln -snf /usr/share/zoneinfo/$HOST_TZ /etc/localtime
echo $HOST_TZ | sudo tee /etc/timezone
export TZ=$HOST_TZ
fi

CONT_UID=$(id -u developer)
CONT_GID=$(id -g developer)
if [[ $CONT_UID -ne $HOST_UID ]] || [[ $CONT_GID -ne $HOST_GID ]]; then
# Update user and group ID to match host
sudo usermod -u $HOST_UID developer
sudo groupmod -g $HOST_GID developer
fi

# Source ROS setup script
if [[ -e /home/developer/bag_ws/install/setup.bash ]]; then
source "/home/developer/bag_ws/install/setup.bash"
else
source /opt/custom_ws/install/setup.bash
fi

exec "$@"
WORKDIR=$(pwd)

exec gosu developer bash -c "cd $WORKDIR && exec $*"

0 comments on commit 0b7514f

Please sign in to comment.