Skip to content

7. Docker

Anthony Tan edited this page Oct 16, 2023 · 14 revisions

Docker

Docker is a powerful platform for developing, shipping, and running applications in a consistent and efficient manner. It utilizes containerization technology to package an application and all its dependencies into a standardized unit called a "container." These containers can run on any system that supports Docker, ensuring consistency across different environments, such as development, testing, and production.

Docker simplifies the process of creating, deploying, and scaling applications, making it easier for developers and operations teams to work together seamlessly. It provides a lightweight, isolated environment for applications, allowing them to run consistently across various infrastructure setups, from local development machines to cloud-based servers. Docker has become a fundamental tool in modern software development and deployment workflows, enabling faster, more reliable application delivery.

We hope to use docker to run ROS on different operating systems without the need to dual boot or use a virtual machine. Our docker images are hosted on docker hub. The images come with ros and all dependencies installed.

X11

X Servers and X11 forwarding are key components of the X Window System (X11), which is used for graphical user interfaces on Unix-like systems. Here's an explanation of both terms and how X11 forwarding can be used from containers:

X Server:

  • An X Server is a software component responsible for managing the graphical display of applications in the X Window System. It runs on the computer where the display hardware is located (usually the user's local machine).
  • The X Server is responsible for rendering windows, handling input from devices like the mouse and keyboard, and managing the communication between applications and the display.
  • It provides a graphical framework that allows multiple applications to run simultaneously in separate windows on the same desktop.

X11 Forwarding:

  • X11 Forwarding is a feature of the X Window System that enables you to run graphical applications on a remote machine but display them on your local machine's desktop.
  • When you SSH into a remote server with X11 forwarding enabled, it sets up a secure channel for the X Server on the remote machine to communicate with the X Server on your local machine.
  • This allows you to run graphical applications on the remote server, and the application's graphical output is forwarded to your local X Server for display. It also forwards mouse and keyboard input back to the remote application.
  • X11 Forwarding is particularly useful when you need to run GUI applications on a server or container located elsewhere, but you want to interact with them as if they were running locally on your desktop.

Ubuntu

After cloning AUV-2024, enter the catkin_ws folder and run xhost +local:host. This relaxes X11 server permissions allowing graphical application to be run from within the container. This method has some security vulnerabilities. More secure methods are detailed here.

Install docker on Ubuntu

Run the following commands:

sudo apt-get update

sudo apt-get install ca-certificates curl gnupg

sudo install -m 0755 -d /etc/apt/keyrings

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

sudo chmod a+r /etc/apt/keyrings/docker.gpg

Add the repository to Apt sources:

echo \ "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

Install docker with apt:

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Test the docker installation:

sudo docker run hello-world

Spin up the container

Enter the Docker directory of AUV-2024 and run docker compose up. That's it. If the x11 permission are set and docker is installed, this will pull the image from docker hub (only needs to do this step once) and creates a container. The docker compose file also mounts the AUV-2024 from your file system into the container meaning that changes in the container are reflected on the host system. Git changes can be tracked from outside the container and changes can be made within the container.

Windows

Install docker on windows by following the instructions on this page. Docker on windows is a little weird and has two backend options. The WSL 2 version is the only one that has been tested. After installing docker, enter the Docker folder and run compose-windows.bat to spin up the container.

How to develop in the container

It is recommended you install the docker and remote development extensions in vs code. This allows you to create vscode windows in the container by navigating to the docker tab in vscode, right clicking on the container, and attaching visual studio code.

GPU usage in the container

To use your dedicated gpu in the container, comment out the deploy section of the compose.yml file. Install nvidia-container-toolkit and restart your computer. Now when you docker compose up, your gpu will be visible in the container. For some reason this breaks gazebo, but gazebo runs well without a gpu. This is useful for training yolo models without having to install ultralytics on your machine.

To test your gpu, open python and run import torch and torch.cuda.is_available().