This folder contains a Docker-based development environment tailored for a standard ROS 2 workspace. It’s designed not just to work — but to help you understand how it works. This tutorial will walk you through the building blocks of Docker in a learning-oriented, hands-on way.
Before getting started, make sure you have Docker installed:
- Docker Desktop (macOS/Windows)
- Docker Engine (Linux)
- On Linux, prefix commands with
sudo, or configure Docker as a non-root user:
👉 Manage Docker as a non-root user
- On Linux, prefix commands with
This setup assumes your local file tree follows a standard ROS 2 workspace layout:
ros2_ws/
├── build/
├── log/
├── install/
└── src/
└── software-learning-period/
└── docker/
├── Dockerfile
├── build.sh
└── run.shIf you haven't already:
git clone git@github.com:vortexntnu/software-learning-period.git
cd software-learning-periodcd docker
chmod +x build.sh
sudo ./build.shYou may need to use sudo for Docker commands unless your user is added to the docker group. See: Manage Docker as a non-root user
cd docker
chmod +x build.sh
./build.shOn macOS, Docker Desktop handles permissions, so sudo is usually not needed.
What this does:
- Builds a Docker image using the Dockerfile in this directory.
- Tags the image as
software-learning-period:latest.
Inside the Dockerfile, you’ll find key instructions:
FROM: Defines the base image (ros:humble)COPY: Copies your ROS workspace filesCMD: Defines the default startup command (bash)
chmod +x run.sh
sudo ./run.shchmod +x run.sh
./run.shWhat this does:
- Starts a new interactive container from the image you built
- Mounts your ROS workspace from your host into /ros2_ws inside the container
- Opens a Bash shell so you can start working with ROS 2 right away
Once inside the container:
colcon build
ros2 launch my_package my_launch_file.launch.pyAll build artifacts (build/, install/, log/) will remain on your host since the volume is mounted into the container.
Here are some helpful Docker commands you can reference:
| Command | Description |
|---|---|
docker ps -a |
List all running and stopped containers |
docker images |
Show all locally available images |
docker build -t <tag> . |
Build image from a Dockerfile |
docker run -it <image> |
Run container interactively |
docker rm <container> |
Remove a stopped container |
docker rmi <image> |
Remove an image |
docker image prune |
Remove unused images |
One of the first things you'll notice when working in a container is that anything you install manually (e.g. with apt) is lost once the container is stopped and removed. To make installed tools available permanently, you must bake them into the image using the Dockerfile.
Let's try it!
You’ll now modify the Dockerfile to install a common tool: curl. This is just an example — the same approach works for Python packages, ROS tools, or anything else you need.
- Open the file:
docker/Dockerfile - Add the following line just before the
COPY . .line:
RUN apt update && apt install -y curlYour Dockerfile will now look like this:
# ------------------------------------------------------------------------------
# Base Image
# ------------------------------------------------------------------------------
ARG BASE_IMAGE=ros:humble
FROM ${BASE_IMAGE}
# ------------------------------------------------------------------------------
# Runtime Configuration
# ------------------------------------------------------------------------------
USER root
SHELL ["/bin/bash", "-c"]
ARG DEBIAN_FRONTEND=noninteractive
# ------------------------------------------------------------------------------
# Workspace Setup
# ------------------------------------------------------------------------------
ENV WORKSPACE=/ros2_ws
WORKDIR ${WORKSPACE}
# ------------------------------------------------------------------------------
# Install system dependencies
# ------------------------------------------------------------------------------
RUN apt update && apt install -y curl
# ------------------------------------------------------------------------------
# Copy Workspace Files
# ------------------------------------------------------------------------------
COPY . .
# ------------------------------------------------------------------------------
# Default Startup Command
# ------------------------------------------------------------------------------
CMD ["bash"]- Rebuild the image
./build.sh- Run the container:
./run.sh- Inside the container, verify:
curl --versionYou’ve now added a dependency to the image itself — no need to reinstall it every time you start a new container!
Tip: Whenever you find yourself installing something manually inside the container, ask yourself: Should this go in the Dockerfile instead?You now have a working introduction to using Docker with a ROS 2 workspace — complete with:
- A preconfigured Dockerfile
- Build and run scripts
- Workspace volume mounting
- Persistent image customization
This setup serves as a reusable starting point for other ROS 2 projects. Feel free to copy the entire docker/ folder into other repositories and adapt it to fit your needs.