0
I’m new to Docker and I need help putting two images together.
First, I have these Dockerfile files / Docker-Compose, for a Docker Container with ROS. Alone, it works fine.
Dockerfile:
ARG FROM_IMAGE=ros:foxy
ARG OVERLAY_WS=/opt/ros/overlay_ws
# multi-stage for caching
FROM $FROM_IMAGE AS cacher
# clone overlay source
ARG OVERLAY_WS
WORKDIR $OVERLAY_WS/src
RUN echo "\
repositories: \n\
ros2/codigo_gustavo: \n\
type: git \n\
url: https://github.com/GustavoLLima/codigo_gustavo.git \n\
version: master \n\
" > ../overlay.repos
RUN vcs import ./ < ../overlay.repos
# copy manifests for caching
WORKDIR /opt
RUN mkdir -p /tmp/opt && \
find ./ -name "package.xml" | \
xargs cp --parents -t /tmp/opt && \
find ./ -name "COLCON_IGNORE" | \
xargs cp --parents -t /tmp/opt || true
# multi-stage for building
FROM $FROM_IMAGE AS builder
# install overlay dependencies
ARG OVERLAY_WS
WORKDIR $OVERLAY_WS
COPY --from=cacher /tmp/$OVERLAY_WS/src ./src
RUN . /opt/ros/$ROS_DISTRO/setup.sh && \
apt-get update && rosdep install -y \
--from-paths \
src \
--rosdistro \
foxy \
&& rm -rf /var/lib/apt/lists/*
# build overlay source
COPY --from=cacher $OVERLAY_WS/src ./src
ARG OVERLAY_MIXINS="release"
RUN . /opt/ros/$ROS_DISTRO/setup.sh && \
colcon build \
--packages-select \
codigo_gustavo \
--mixin $OVERLAY_MIXINS
# source entrypoint setup
ENV OVERLAY_WS $OVERLAY_WS
RUN sed --in-place --expression \
'$isource "$OVERLAY_WS/install/setup.bash"' \
/ros_entrypoint.sh
Docker-Compose.yml:
version: '3'
services:
talker:
build: ./
command: ros2 run codigo_gustavo talker
listener:
build: ./
environment:
- "PYTHONUNBUFFERED=1"
command: ros2 run codigo_gustavo listener
deploy:
mode: replicated
replicas: 2
Then I have other Dockerfile / Docker-Compose files for a Docker Container running Netlogo. Again, it works fine.
Dockerfile:
FROM openjdk:8-jdk
LABEL maintainer="Allen Lee <[email protected]>"
ARG NETLOGO_HOME=/opt/netlogo
ARG NETLOGO_VERSION=6.0.4
ENV LC_ALL=C.UTF-8 \
LANG=C.UTF-8 \
NETLOGO_TARBALL=NetLogo-$NETLOGO_VERSION-64.tgz
ENV NETLOGO_URL=https://ccl.northwestern.edu/netlogo/$NETLOGO_VERSION/$NETLOGO_TARBALL
WORKDIR /opt
RUN wget $NETLOGO_URL && tar xzf $NETLOGO_TARBALL && ln -sf "NetLogo $NETLOGO_VERSION" netlogo \
&& rm -f $NETLOGO_TARBALL
Docker-Compose.yml:
version: '3'
services:
modelo1:
build: ./
command: tail -f /dev/null
volumes:
- ./teste:/teste
volumes:
teste:
Now the problem: I am trying to put these two codes together, to use only one Dockerfile / Docker-Compose file, making it easier to run. The problem is that I was able to make both containers, but when I try to run Netlogo (via netlogo headless), Container cannot find Java (Netlogo dependency). I checked the directory and it seems that Java is not installed. Workspace comes with two folders, Netlogo and ROS.
Dockerfile:
#--------------Netlogo Instalation--------------
ARG FROM_IMAGE=ros:foxy
ARG OVERLAY_WS=/opt/ros/overlay_ws
#FROM openjdk:8-jdk AS netlogo_cache
FROM openjdk:8-jdk
LABEL maintainer="Allen Lee <[email protected]>"
ARG NETLOGO_HOME=/opt/netlogo
ARG NETLOGO_VERSION=6.0.4
ENV LC_ALL=C.UTF-8 \
LANG=C.UTF-8 \
NETLOGO_TARBALL=NetLogo-$NETLOGO_VERSION-64.tgz
ENV NETLOGO_URL=https://ccl.northwestern.edu/netlogo/$NETLOGO_VERSION/$NETLOGO_TARBALL
WORKDIR /opt
RUN wget $NETLOGO_URL && tar xzf $NETLOGO_TARBALL && ln -sf "NetLogo $NETLOGO_VERSION" netlogo \
&& rm -f $NETLOGO_TARBALL
#--------------ROS------------------------
#ARG FROM_IMAGE=ros:foxy
#ARG OVERLAY_WS=/opt/ros/overlay_ws
# multi-stage for caching
FROM $FROM_IMAGE AS cacher
# clone overlay source
ARG OVERLAY_WS
WORKDIR $OVERLAY_WS/src
RUN echo "\
repositories: \n\
ros2/codigo_gustavo: \n\
type: git \n\
url: https://github.com/GustavoLLima/codigo_gustavo.git \n\
version: master \n\
" > ../overlay.repos
RUN vcs import ./ < ../overlay.repos
# copy manifests for caching
WORKDIR /opt
RUN mkdir -p /tmp/opt && \
find ./ -name "package.xml" | \
xargs cp --parents -t /tmp/opt && \
find ./ -name "COLCON_IGNORE" | \
xargs cp --parents -t /tmp/opt || true
# multi-stage for building
FROM $FROM_IMAGE AS builder
# install overlay dependencies
ARG OVERLAY_WS
WORKDIR $OVERLAY_WS
COPY --from=cacher /tmp/$OVERLAY_WS/src ./src
RUN . /opt/ros/$ROS_DISTRO/setup.sh && \
apt-get update && rosdep install -y \
--from-paths \
src \
--rosdistro \
foxy \
&& rm -rf /var/lib/apt/lists/*
# build overlay source
COPY --from=cacher $OVERLAY_WS/src ./src
ARG OVERLAY_MIXINS="release"
RUN . /opt/ros/$ROS_DISTRO/setup.sh && \
colcon build \
--packages-select \
codigo_gustavo \
--mixin $OVERLAY_MIXINS
# source entrypoint setup
ENV OVERLAY_WS $OVERLAY_WS
RUN sed --in-place --expression \
'$isource "$OVERLAY_WS/install/setup.bash"' \
/ros_entrypoint.sh
#COPY --from=netlogo_cache /opt/netlogo ./netlogo
COPY --from=0 /opt/netlogo ./netlogo
Docker-Compose.yml:
version: '3'
services:
talker:
build: ./
command: ros2 run codigo_gustavo talker
listener:
build: ./
environment:
- "PYTHONUNBUFFERED=1"
command: ros2 run codigo_gustavo listener
deploy:
mode: replicated
replicas: 2
modelo1:
build: ./
command: tail -f /dev/null
volumes:
- ./teste:/teste
volumes:
teste:
Error context:
cd /opt/ros/overlay_ws
./netlogo/netlogo-headless.sh --model /teste/WS2.nlogo --experiment experiment1 --spreadsheet /teste/teste2.csv
JAVA_HOME undefined, using java from path. For control over exact java version, set JAVA_HOME
./netlogo/netlogo-headless.sh: line43: java: command not found
Any idea? What should I do? What am I doing wrong?
Thank you!