Docker usage

Docker usage1. Start the image2. ROS environment construction2.1. Update system software2.2. Determine the language environment2.2.1. Verify the system environment2.2.2. Set the UTF-8 environment2.3、Set software source2.4、Set key2.5. Install ROS1 desktop version2.6, install ROS1 dependencies2.7, rosdep initialization2.8, Setting environment variables2.8.1, Temporary settings2.8.2, Automatic settings (recommended)3. Submit the image4. Verify the image/ROS4.1. Start the image4.2. Verify the ROS environment

The tutorial builds ROS1:Melodic environment based on ubuntu:18.04!

1. Start the image

Start the ubuntu:18.04 image in interactive mode:

image-20250105145841732

2. ROS environment construction

Administrator privileges are not required in Docker. If the host installs the ROS environment, sudo needs to be added to the command.

2.1. Update system software

To install the ROS1 environment, you generally need to ensure that the system software package is up to date:

image-20250105150409953

2.2. Determine the language environment

Make sure the system language environment supports UTF-8!

2.2.1. Verify the system environment

image-20250105150553931

2.2.2. Set the UTF-8 environment

If the system language does not support the UTF-8 environment, enter the following commands line by line in the terminal:

image-20250105150825784

2.3、Set software source

image-20250105151200285

2.4、Set key

image-20250105151255171

2.5. Install ROS1 desktop version

ROS desktop version includes ROS1 core functions, common tools and libraries:

image-20250105151509965

You need to select the region and city by yourself: not demonstrated here

image-20250105153026285

2.6, install ROS1 dependencies

image-20250105153047221

2.7, rosdep initialization

If rosdep init displays the error message ERROR: cannot download default sources list from: https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list Website may be down., visit https://www.ipaddress.com/ and search for the raw.githubusercontent.com domain name, and fill the IP address obtained in the /etc/hosts file:

image-20250105153657366

Re-run:

image-20250105153805076

2.8, Setting environment variables

2.8.1, Temporary settings

Refresh the current terminal environment variables:

2.8.2, Automatic settings (recommended)

Open the terminal to automatically refresh the environment variables: Open the terminal to automatically refresh the .bashrc file content

image-20250105154037355

3. Submit the image

Only by submitting a new image locally can the previously built ROS environment be saved. Otherwise, the next time you start the docker image, there will still be no ROS environment in the container.

Note: Modify according to the actual CONTAINER ID

image-20250105154849346

After saving, you can close the ubuntu:18.04 container:

image-20250105155221111

4. Verify the image/ROS

4.1. Start the image

Start the ros_melodic:1.0 image in interactive mode: Since the turtle case needs to be displayed in the graphical interface, Docker needs to be allowed to access the X Display

4.2. Verify the ROS environment

Use the turtle case to test the ROS environment: open three terminals to enter the same container, and then run the following commands respectively

Note: The mouse must stay in the third command window to control the turtle

image-20250105162952201