Docker basics
Docker is optional for the ROS 2 exercises, but it is useful when a tool should run without installing all of its dependencies on the host computer. This repository also uses Docker Compose to export the workshop slides without installing Node.js locally.
Follow the official Docker Engine installation instructions for
Ubuntu. Complete Docker’s
post-installation steps if workshop commands should run without sudo.
Membership in the docker group grants elevated privileges, so only enable it
on a computer where that access is appropriate.
Core concepts
Term |
Meaning |
|---|---|
Image |
A read-only template containing an application and its dependencies |
Container |
A running or stopped instance of an image |
Dockerfile |
Instructions for building an image |
Compose file |
Configuration for one or more related containers |
Volume |
Data or a directory mounted into a container |
Verify Docker
docker --version
docker compose version
docker run --rm hello-world
The final command downloads a small test image, runs it, and removes the container after it exits.
Images
Download an image:
docker pull ubuntu:24.04
List local images:
docker images
Build an image from a Dockerfile in the current directory:
docker build -t my_image .
Containers
Start an interactive Ubuntu container:
docker run --rm -it ubuntu:24.04
The --rm option removes the container when it exits.
Start and name a container:
docker run -it --name my_container ubuntu:24.04
List running containers or all containers:
docker ps
docker ps -a
Start an existing stopped container and open a shell:
docker start my_container
docker exec -it my_container bash
Stop and remove it:
docker stop my_container
docker rm my_container
Docker Compose
Compose reads a compose.yaml file and manages its services together.
docker compose up
docker compose ps
docker compose logs
docker compose down
Run a one-off service and remove its container afterward:
docker compose run --rm SERVICE_NAME
Rebuild service images before starting:
docker compose up --build
Exercise
Run an interactive
ubuntu:24.04container.Inside the container, display the Ubuntu release information.
Exit the container and confirm that it was removed.
docker run --rm -it ubuntu:24.04
cat /etc/os-release
exit
docker ps -a
Using ROS 2 with Docker
Tutorial material: https://github.com/ipa-may/docker_ros2_tutorial