Ask Your Question
1

How to build using Colcon inside a Dockerfile

asked 2021-03-14 19:36:26 -0500

jandaa gravatar image

updated 2021-03-16 09:55:27 -0500

I'm trying to use docker to build and run a ROS2 node, however in order for Colcon to build the node as an instruction in the Dockerfile, it must first have ROS2 sourced. It seems though that you cannot source a script in a dockerfile instruction, so is there a way to build a Colcon workspace as part of a dockerfile?

Essentially what I'm trying to do assuming a colcon workspace has been copied to the image is:

RUN /bin/bash -c "source /opt/ros/eloquent/setup.sh" && colcon build

edit retag flag offensive close merge delete

Comments

1

I suggest you add the "Update" as an answer and accept it instead of updating the question.

jeremya gravatar image jeremya  ( 2021-03-16 08:10:25 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
2

answered 2021-03-17 17:07:25 -0500

ruffsl gravatar image

Instead of using the source in bash, you can use the dot operator instead, as it's supported in dash (the default shell in ubuntu based images)

https://wiki.ubuntu.com/DashAsBinSh

For example:

RUN . /opt/ros/$ROS_DISTRO/setup.sh && \
    colcon build

https://github.com/ros-planning/navig...

You can also change the default shell in the Dockerfile:

https://docs.docker.com/engine/refere...

but I'd suggest keeping it simple with the dot operator as above.

edit flag offensive delete link more

Comments

Thanks that works as well!

jandaa gravatar image jandaa  ( 2021-03-17 19:27:20 -0500 )edit
1

answered 2021-03-15 16:50:29 -0500

jeremya gravatar image

Instead of

RUN /bin/bash -c "source /opt/ros/eloquent/setup.sh" && colcon build

try moving the double quote:

RUN /bin/bash -c "source /opt/ros/eloquent/setup.sh && colcon build"

edit flag offensive delete link more

Comments

Ah you're right thank you!

jandaa gravatar image jandaa  ( 2021-03-16 09:54:58 -0500 )edit
0

answered 2021-03-16 09:55:57 -0500

jandaa gravatar image

I found you can also write a script and execute it in the instruction. For example:

#!/bin/bash
source /opt/ros/"${ROS_DISTRO}"/setup.bash
colcon build

and inside the docker file RUN build.sh

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2021-03-14 19:36:26 -0500

Seen: 81 times

Last updated: Mar 17