<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Myron Rodrigues on Medium]]></title>
        <description><![CDATA[Stories by Myron Rodrigues on Medium]]></description>
        <link>https://medium.com/@mro47?source=rss-afa769b7de03------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uif7ElXqv__zn31qIR2avw.jpeg</url>
            <title>Stories by Myron Rodrigues on Medium</title>
            <link>https://medium.com/@mro47?source=rss-afa769b7de03------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 21:55:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mro47/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Dev Containers + ROS2]]></title>
            <link>https://medium.com/@mro47/dev-containers-ros2-f6010c7e2f97?source=rss-afa769b7de03------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6010c7e2f97</guid>
            <category><![CDATA[devcontainer]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[robot-operating-system]]></category>
            <category><![CDATA[robotics]]></category>
            <category><![CDATA[ros2]]></category>
            <dc:creator><![CDATA[Myron Rodrigues]]></dc:creator>
            <pubDate>Sun, 11 Aug 2024 11:31:24 GMT</pubDate>
            <atom:updated>2024-08-14T19:56:18.105Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y6GpUtoZXdUPwV6BpFkTZg.png" /></figure><p>Development or Dev containers are simply put, docker containers that are configured to provide fully featured development environments. Here we will learn how to configure and build dev containers to create a fully featured ROS2 environment.</p><h3>Why use Dev containers?</h3><ul><li><strong>Isolation</strong>: Ensures that the ROS2 environment is consistent and isolated from the host system, avoiding conflicts with other installed software.</li><li><strong>Reproducibility</strong>: Allows for the creation of a consistent development environment that can be shared among team members, ensuring everyone uses the same tools and dependencies.</li><li><strong>Portability</strong>: Containers can be run on any system that supports Docker, making it easy to move between different machines and environments.</li><li><strong>Simplified Dependency Management</strong>: All dependencies and tools required for ROS2 development are specified within the container, simplifying the setup process.</li><li><strong>Version Control</strong>: Different versions of ROS2 or its dependencies can be managed easily by switching between different container images.</li></ul><h3>How to set up a Dev container?</h3><p>There are 3 different types of files that are needed to set up a dev container.</p><ol><li><strong>Dockerfile:</strong> Instructions to build the containers.</li><li><strong>docker-compose.yml:</strong> provide the configuration to build, run and combine the images built using Dockerfile.</li><li><strong>devcontainer.json:</strong> This file uses the docker-compose.yml files to build the services and also provides configuration for vs-code to work with the target service.</li></ol><p>Lets set these up for a container layer structure as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*MxsFNVbIaOWVS4k1Zptpcg.png" /><figcaption>Fig 1: Dev container architecture for a ROS2 computer vision dev environment.</figcaption></figure><h4>1. Dockerfile</h4><p><a href="https://docs.docker.com/build/building/multi-stage/">Multistage</a> builds are used to separate container functionalities. Multistage builds are useful when extending the functionality of the container for different development or production environments.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9438ff55b4862b05df524d16938ab989/href">https://medium.com/media/9438ff55b4862b05df524d16938ab989/href</a></iframe><p>The example here builds a computer vision stage over the base image and finally the development stage over it. This can be swapped to build other robotics functionalities related to the projects one works on. The file can be found <a href="https://github.com/MRo47/ros2_tools/blob/main/ros2_dev_container/.devcontainer/Dockerfile">here</a>.</p><p>To keep dependencies clear from the builds they are listed in separate files with names apt-*-packages. The following Dockerfile command parses and installs the dependencies.</p><pre>RUN apt-get update &amp;&amp; \<br>    apt-get install -y $(cut -d# -f1 &lt;/tmp/apt-base-packages | envsubst) \<br>    &amp;&amp; rm -rf /var/lib/apt/lists/* /tmp/apt-base-packages</pre><h4>2. docker-compose.&lt;type&gt;.yml</h4><p>These files are separated per type (base, cv, dev) to keep their functionality separate, which could be later combined in the devcontainer.json file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f107444b4e2e04afc97733c736353ab2/href">https://medium.com/media/f107444b4e2e04afc97733c736353ab2/href</a></iframe><p>To extend any service from a Dockerfile set the extends: field and specify the docker-compose.*.yml file under file: which has the service and the name of the service in that file as service: . These files can be found <a href="https://github.com/MRo47/ros2_tools/tree/main/ros2_dev_container/.devcontainer">here</a>.</p><h4>3. devcontainer.json</h4><p>We combine the services we built using docker-compose.yml file above to create the dev container.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f167d716e65298935efc982dca14a1c/href">https://medium.com/media/9f167d716e65298935efc982dca14a1c/href</a></iframe><p>name: is the name of the dev container.</p><p>dockerComposeFile: will be all the compose files used to build this dev container, they should appear in order they are used, i.e. base &gt; cv &gt; dev.</p><p>service: will be the service in which we will work in, dev obviously in our case.</p><p>workspaceFolder: will be the directory inside the dev container that will be opened in vs-code when the container is started.</p><p>For more info see <a href="https://code.visualstudio.com/docs/devcontainers/create-dev-container">this</a> vs-code article.</p><h3>Build</h3><h4>1. Exporting environment variables</h4><p>Before building the containers a .env file must be configured. This contains the users UID, GID, name and group name which will be used to create a non-root user inside the dev container. This will also ensure the user has permissions to the mounted files and directories.</p><p>To generate the .env file in .devcontainer</p><pre># from ros2_dev_container<br>bash export_env.sh</pre><h4>2. Build the container in vs-code</h4><p>Make sure you have the <a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers">Dev Containers</a> extension installed in vs-code.</p><p>Open ros2_dev_container directory in vs-code &gt; press F1 &gt; Dev Containers: Rebuild and Reopen in Container.</p><p>Usually once built vs-code will ask you to open this directory in container, which you can say yes. Or from command palette F1 and run Reopen in Container.</p><blockquote><strong><em>NOTE</em></strong><em> if the build fails, reopen in local folder option will show you logs. also </em><a href="https://code.visualstudio.com/docs/devcontainers/create-dev-container#_full-configuration-edit-loop"><em>see</em></a></blockquote><h4>3. For non vs-code users</h4><p>The initial setup remains the same. Generate the .env file in .devcontainer.</p><pre># from ros2_dev_container<br>bash export_env.sh</pre><h4>3.a. Using docker-compose</h4><ul><li>To build or run the containers</li></ul><pre># from ros2_dev_container<br>docker-compose -f .devcontainer/docker-compose.base.yml -f .devcontainer/docker-compose.cv.yml -f .devcontainer/docker-compose.dev.yml up -d</pre><ul><li>To get shell access into the container while its running. Get the name of the dev container from command above and run the following from another terminal.</li></ul><pre>docker exec -it &lt;container_name&gt; /bin/bash</pre><ul><li>To stop the containers.</li></ul><pre># from ros2_dev_container<br>docker compose -f .devcontainer/docker-compose.base.yml -f .devcontainer/docker-compose.cv.yml -f .devcontainer/docker-compose.dev.yml down</pre><h4>3.b. Using devcontainers-cli</h4><p>The <a href="https://github.com/devcontainers/cli">cli</a> version of the vs-code extension can also be used.</p><ul><li>To build and start the container. This achieves the same as running Devcontainers: Rebuild from vs-code&#39;s command prompt.</li></ul><pre># from ros2_dev_container<br>devcontainer up --remove-existing-container --workspace-folder .</pre><ul><li>To get shell access into the container while its running. This achieves the equivalent as running Devcontainers: Reopen in Container in vs-code.</li></ul><pre># from ros2_dev_container<br>devcontainer exec --workspace-folder . bash</pre><ul><li>To stop the container</li></ul><pre># To list all running containers<br>docker ps<br><br># To stop the container by its ID<br>docker stop &lt;container_id&gt;<br><br># To remove the container entirely<br>docker rm &lt;container_id&gt;</pre><h3>Examples</h3><p>The dev containers we created above can be now used in various configurations as below and can be extended for complex production environments.</p><h4>Production environments</h4><p>The dev environment can simply be switched for a production container that usually will have dependency install instructions, launch files, config files and launch scripts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*xC4q-1Jp8PyUxXQtWrLR3Q.png" /><figcaption>Fig 2: Use in production environment</figcaption></figure><h4>Other ROS2 environments</h4><p>Developers can swap the computer vision container for example here the navigation container that builds over the same ROS2 base. This will ensure they start from the same base environments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*gudu59BUtoKbiQhbZNhk8w.png" /><figcaption>Fig 3: Navigation development environment</figcaption></figure><h4>Combined production environment</h4><p>Finally the computer vision and navigation environments can be combined as below and a final production environment can be built that combines the configurations and launch scripts of both the development environments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*EsaInP4wE8BArczf2dJBDA.png" /><figcaption>Fig 4: Production environment with combined computer vision and navigation stacks</figcaption></figure><h3>Conclusion</h3><p>Leveraging Docker containers for ROS2 development offers significant advantages, including isolation, reproducibility, and simplified dependency management. By utilizing dev containers, developers can create consistent and portable development environments that are easy to share and maintain. Whether you choose to use vs-code’s dev containers or a more manual approach, this method will streamline your ROS2 development, making it more efficient and reliable.</p><p>For any <a href="https://github.com/MRo47/ros2_tools/issues">issues</a> and <a href="https://github.com/MRo47/ros2_tools/pulls">pull requests</a> the code is <a href="https://github.com/MRo47/ros2_tools">here</a>.</p><h3>Thanks</h3><p><a href="https://github.com/mcarfagno">Marcello</a> for reviewing and editing the code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6010c7e2f97" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>