Skip to main content

Container Commands

A container is a running instance of an image. This page covers the high-frequency operations for starting, entering, logging, and stopping containers. docker run is the single most-used command.

Start a container (docker run)​

docker run is the core command. Here is a table of the most common flags:

FlagPurposeExample
-dRun detached (background)docker run -d nginx
-pPort mapping host:container-p 8080:80
-vVolume mount host:container-v $PWD/data:/data
-eInject environment variable-e ROS_DOMAIN_ID=1
--nameName the container (easier to manage)--name ros-node
--restartRestart policy on exit--restart unless-stopped
--rmAuto-remove container on exitdocker run --rm ubuntu

A ROS 2 node example, running in the background with port mapping and a restart policy:

Linux
docker run -d \
--name ros-node \
-p 11311:11311 \
-e ROS_DOMAIN_ID=1 \
--restart unless-stopped \
ros:humble \
ros2 run demo_nodes_cpp talker

💡 For interactive image debugging, add -it and override the default command to drop into a shell: docker run -it --rm ubuntu bash.

List running containers​

Running containers only:

Linux
docker ps

All containers, including stopped ones:

Linux
docker ps -a

Enter a running container​

Open an interactive terminal (the most common troubleshooting step):

Linux
docker exec -it ros-node bash

Run a one-off command without an interactive shell:

Linux
docker exec ros-node ros2 node list

View logs​

Follow container logs in real time (-f behaves like tail -f):

Linux
docker logs -f ros-node

Stop and remove​

Graceful stop (sends SIGTERM, waits up to 10s by default):

Linux
docker stop ros-node

Force stop (immediate SIGKILL):

Linux
docker kill ros-node

Remove a stopped container:

Linux
docker rm ros-node
tip

The troubleshooting trio

When a container misbehaves, locate the issue in this order:

Linux
docker ps -a # 1. check status and exit code
docker logs ros-node # 2. check startup logs
docker exec -it ros-node bash # 3. enter the container to investigate

Resource usage​

Live CPU, memory, and network usage per container:

Linux
docker stats
Join Us