Skip to content

Commit 559fd2c

Browse files
committed
pass to docker compose with internal network for simulation
1 parent ec72794 commit 559fd2c

File tree

6 files changed

+249
-2
lines changed

6 files changed

+249
-2
lines changed

Dockerfile DockerFiles/Dockerfile

File renamed without changes.

build.bash DockerFiles/build.bash

File renamed without changes.

run.bash DockerFiles/run.bash

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ then
1515
touch $XAUTH
1616
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
1717
fi
18-
19-
xhost +
18+
echo $XAUTH
19+
# xhost +
2020

2121
docker run \
2222
--net=host \

Dockerfile_1

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
ARG BASE_IMAGE=osrf/ros
2+
ARG BASE_TAG= jazzy-desktop-full
3+
4+
FROM ${BASE_IMAGE}:${BASE_TAG}
5+
6+
# set the environment variable with the command ENV <key>=<value>, it can be replaced online
7+
ENV DEBIAN_FRONTEND=noninteractive
8+
ENV GZ_VERSION=harmonic
9+
## arg ros2 distro
10+
ARG DISTRO=humble
11+
# RUN is used to execute and add new layer on top of the base immage
12+
RUN apt-get update
13+
14+
15+
RUN apt-get install -y ros-${DISTRO}-plotjuggler
16+
RUN apt-get install -y ros-${DISTRO}-ros-gz
17+
RUN apt-get install -y \
18+
ros-${DISTRO}-joint-state-publisher \
19+
ros-${DISTRO}-joint-state-publisher-gui \
20+
ros-${DISTRO}-gz-ros2-control \
21+
ros-${DISTRO}-teleop-twist-joy \
22+
ros-${DISTRO}-joy \
23+
ros-${DISTRO}-pinocchio \
24+
ros-${DISTRO}-ros2-control \
25+
ros-${DISTRO}-ros2-controllers \
26+
ros-${DISTRO}-xacro \
27+
ros-${DISTRO}-rosbag2-storage-mcap \
28+
ros-${DISTRO}-plotjuggler-ros \
29+
pipx \
30+
chrony \
31+
tmux python3-pip\
32+
xterm \
33+
libeigen3-dev \
34+
nano \
35+
ros-${DISTRO}-rviz2 \
36+
nautilus \
37+
iputils-ping \
38+
iproute2 \
39+
python3-rosdep \
40+
&& apt-get clean
41+
RUN apt-get install -y \
42+
ros-${DISTRO}-rmw-cyclonedds-cpp \
43+
&& apt-get clean
44+
RUN apt-get install -y curl lsb-release gnupg
45+
RUN curl https://packages.osrfoundation.org/gazebo.gpg --output /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg
46+
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null
47+
RUN echo " CURL DONE"
48+
49+
RUN sudo apt-get update
50+
RUN sudo apt-get install -y gz-harmonic
51+
RUN echo "Ignition Installed"
52+
53+
# install
54+
# Adapt your desired python version here
55+
# ENV PATH=/opt/openrobots/bin:$PATH
56+
# ENV PKG_CONFIG_PATH=/opt/openrobots/lib/pkgconfig:$PKG_CONFIG_PATH
57+
# ENV LD_LIBRARY_PATH=/opt/openrobots/lib:$LD_LIBRARY_PATH
58+
# ENV PYTHONPATH=/opt/openrobots/lib/python3.10/site-packages:$PYTHONPATH
59+
# ENV CMAKE_PREFIX_PATH=/opt/openrobots:$CMAKE_PREFIX_PATH
60+
# ENV TERM=xterm-256color
61+
62+
ENV DEBIAN_FRONTEND=dialog
63+
64+
# Create a new user
65+
ARG USERNAME=ros
66+
ARG USER_UID=1000
67+
ARG USER_GID=${USER_UID}
68+
RUN if id -u ${USER_UID} ; then userdel `id -un ${USER_UID}` ; fi
69+
RUN groupadd --gid ${USER_GID} ${USERNAME}
70+
RUN useradd --uid ${USER_UID} --gid ${USER_GID} -m ${USERNAME} \
71+
&& apt-get update \
72+
&& apt-get install -y sudo \
73+
&& echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} \
74+
&& chmod 0440 /etc/sudoers.d/${USERNAME}
75+
76+
#Change HOME environment variable
77+
ENV HOME=/home/${USERNAME}
78+
# Choose to run as user
79+
ENV USER=${USERNAME}
80+
81+
USER ${USERNAME}
82+
83+
# ********************************************************
84+
# * Anything else you want to do like clean up goes here *
85+
# ********************************************************
86+
87+
# Install the python packages cosi non vengono installati da root
88+
RUN pipx install numpy
89+
# install gazebo ignition
90+
# RUN sudo apt-get install -y curl lsb-release gnupg
91+
# RUN sudo curl https://packages.osrfoundation.org/gazebo.gpg --output /usr/share/keyrings/pkgs-osrf-archive-keyring.gpgecho "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null
92+
# RUN echo " CURL DONE"
93+
94+
# Set up auto-source of workspace for ros user
95+
ARG WORKSPACE=docker_navigation
96+
WORKDIR /home/ros/${WORKSPACE}
97+
98+
RUN echo "source /opt/ros/${DISTRO}/setup.bash" >> ~/.bashrc
99+
100+
RUN echo "if [ -f ~/${WORKSPACE}/install/setup.bash ]; then source ~/${WORKSPACE}/install/setup.bash; fi" >> /home/ros/.bashrc
101+
RUN echo "export GZ_SIM_SYSTEM_PLUGIN_PATH=/opt/ros/humble/lib/" >> ~/.bashrc
102+
RUN sudo ln -s /usr/include/eigen3/Eigen /usr/include/Eigen
103+
# install gazebo ignition
104+
105+
106+
ENTRYPOINT ["/ros_entrypoint.sh"]
107+
# RUN echo "source /opt/ros/jazzy/setup.bash" >> ~/.bashrc
108+
# RUN echo "source /home/ros/ros2_ws/install/setup.bash 2>/dev/null || true" >> ~/.bashrc

compose.yaml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
services:
2+
ros2_shell:
3+
build:
4+
dockerfile: Dockerfile_1
5+
context: .
6+
container_name: ros2_jammy_it
7+
networks:
8+
- ros2_internal
9+
# Interactive shell settings
10+
stdin_open: true
11+
tty: true
12+
# Network settings
13+
14+
# Environment variables
15+
environment:
16+
- DISPLAY=${DISPLAY}
17+
- QT_X11_NO_MITSHM=1
18+
- XAUTHORITY=/tmp/.docker.xauth
19+
- ROS_DOMAIN_ID=0
20+
- RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
21+
# Shell history
22+
- HISTFILE=/home/ros/.bash_history
23+
- HISTFILESIZE=10000
24+
- RCUTILS_COLORIZED_OUTPUT=1
25+
privileged: true # Fixed spelling and removed duplicate
26+
volumes:
27+
- /tmp/.X11-unix:/tmp/.X11-unix:rw
28+
- /tmp/.docker.xauth:/tmp/.docker.xauth:rw
29+
- ~/.bash_history:/home/ros/.bash_history
30+
- /home/punk-opc/Documents/docker_navigation:/home/ros/docker_simulation_ws
31+
- /dev/input:/dev/input
32+
33+
# Command to source ROS2 environment and start shell
34+
command: >
35+
bash -c "
36+
source /opt/ros/jazzy/setup.bash &&
37+
echo 'ROS2 Jazzy environment loaded' &&
38+
bash
39+
"
40+
devices:
41+
- /dev/dri:/dev/dri
42+
# ros2_joy:
43+
# build:
44+
# dockerfile: Dockerfile_1
45+
# context: .
46+
# container_name: ros2_jammy_joy
47+
# networks:
48+
# - ros2_internal
49+
# # Interactive shell settings
50+
# stdin_open: true
51+
# tty: true
52+
# # Network settings
53+
54+
# # Environment variables
55+
# environment:
56+
# - DISPLAY=${DISPLAY}
57+
# - QT_X11_NO_MITSHM=1
58+
# - XAUTHORITY=/tmp/.docker.xauth
59+
# - ROS_DOMAIN_ID=0
60+
# - RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
61+
# # Shell history
62+
# - HISTFILE=/home/ros/.bash_history
63+
# - HISTFILESIZE=10000
64+
# - RCUTILS_COLORIZED_OUTPUT=1
65+
# privileged: true # Fixed spelling and removed duplicate
66+
# volumes:
67+
# - /tmp/.X11-unix:/tmp/.X11-unix:rw
68+
# - /tmp/.docker.xauth:/tmp/.docker.xauth:rw
69+
# - ~/.bash_history:/home/ros/.bash_history
70+
# - /home/punk-opc/Documents/docker_navigation:/home/ros/docker_simulation_ws
71+
# - /dev/input:/dev/input
72+
73+
# # Command to source ROS2 environment and start shell
74+
# command: >
75+
# bash -c "
76+
# source /opt/ros/jazzy/setup.bash &&
77+
# echo 'ROS2 Jazzy environment loaded' &&
78+
# bash
79+
# "
80+
# devices:
81+
# - /dev/dri:/dev/dri
82+
networks:
83+
ros2_internal:
84+
driver: bridge
85+

compose_build.bash

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
# ================================= Edit Here ================================ #
4+
DISTRO=jazzy
5+
# Change these values to use different versions of ROS or different base images. The rest of the script should be left unchanged.
6+
BASE_IMAGE=osrf/ros
7+
BASE_TAG=$DISTRO-desktop-full
8+
IMAGE_NAME=docker_control_simulation
9+
IMAGE_TAG=0.1
10+
11+
USERNAME=ros
12+
USER_UID="$(id -u $USER)"
13+
USER_GID="$(id -g $USER)"
14+
WORKSPACE=docker_simulation_ws
15+
16+
# =============================== Help Function ============================== #
17+
18+
helpFunction()
19+
{
20+
echo ""
21+
echo -e "\t-h --help Script used to build the image."
22+
exit 1 # Exit script after printing help
23+
}
24+
25+
# =============================== BUILD ============================== #
26+
27+
# Auxiliary functions
28+
die() { echo "$*" >&2; exit 2; } # complain to STDERR and exit with error
29+
needs_arg() { if [ -z "$OPTARG" ]; then die "No arg for --$OPT option"; fi; }
30+
no_arg() { if [ -n "$OPTARG" ]; then die "No arg allowed for --$OPT option"; fi; }
31+
32+
# Get the script options. This accepts both single dash (e.g. -a) and double dash options (e.g. --all)
33+
while getopts h-: OPT; do
34+
# support long options: https://stackoverflow.com/a/28466267/519360
35+
if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG
36+
OPT="${OPTARG%%=*}" # extract long option name
37+
OPTARG="${OPTARG#$OPT}" # extract long option argument (may be empty)
38+
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
39+
fi
40+
case "$OPT" in
41+
h | help ) no_arg; helpFunction ;;
42+
esac
43+
done
44+
45+
docker compose build \
46+
--build-arg BASE_IMAGE=$BASE_IMAGE \
47+
--build-arg BASE_TAG=$BASE_TAG \
48+
--build-arg IMAGE_NAME=$IMAGE_NAME \
49+
--build-arg IMAGE_TAG=$IMAGE_TAG \
50+
--build-arg USERNAME=$USERNAME \
51+
--build-arg USER_UID=$USER_UID \
52+
--build-arg USER_GID=$USER_GID \
53+
--build-arg WORKSPACE=$WORKSPACE \
54+
--build-arg DISTRO=$DISTRO

0 commit comments

Comments
 (0)