Docker Containers
Last updated
Last updated
Docker containers are provided for the complete including NuttX and Linux based hardware, simulation, and .
This topic shows how to use the to access the build environment in a local Linux computer.
:::note Dockerfiles and README can be found on . They are built automatically on . :::
:::note PX4 containers are currently only supported on Linux (if you don't have Linux you can run the container ). Do not use boot2docker
with the default Linux image because it contains no X-Server. :::
for your Linux computer, preferably using one of the Docker-maintained package repositories to get the latest stable version. You can use either the Enterprise Edition or (free) Community Edition.
For local installation of non-production setups on Ubuntu, the quickest and easiest way to install Docker is to use the as shown below (alternative installation methods are found on the same page):
The default installation requires that you invoke Docker as the root user (i.e. using sudo
). However, for building the PX4 firmware we suggest to . That way, your build folder won't be owned by root after using docker.
These allow testing of various build targets and configurations (the included tools can be inferred from their names). The containers are hierarchical, such that containers have the functionality of their parents. For example, the partial hierarchy below shows that the docker container with nuttx build tools (px4-dev-nuttx-focal
) does not include ROS 2, while the simulation containers do:
:::tip Typically you should use a recent container, but not necessarily the latest
(as this changes too often). :::
The following instructions show how to build PX4 source code on the host computer using a toolchain running in a docker container. The information assumes that you have already downloaded the PX4 source code to src/PX4-Autopilot, as shown:
For example, to build SITL you would call (from within the /PX4-Autopilot directory):
Or to start a bash session using the NuttX toolchain:
The syntax of a typical command is shown below. This runs a Docker container that has support for X forwarding (makes the simulation GUI available from inside the container). It maps the directory <host_src>
from your computer to <container_src>
inside the container and forwards the UDP port needed to connect QGroundControl. With the -–privileged
option it will automatically have access to the devices on your host (e.g. a joystick and GPU). If you connect/disconnect a device you have to restart the container.
Where,
<host_src>
: The host computer directory to be mapped to <container_src>
in the container. This should normally be the PX4-Autopilot directory.
<container_src>
: The location of the shared (source) directory when inside the container.
<local_container_name>
: A name for the docker container being created. This can later be used if we need to reference the container again.
<container>:<tag>
: The container with version tag to start - e.g.: px4io/px4-dev-ros:2017-10-23
.
<build_command>
: The command to invoke on the new container. E.g. bash
is used to open a bash shell in the container.
The concrete example below shows how to open a bash shell and share the directory ~/src/PX4-Autopilot on the host computer.
:::note We use the host network mode to avoid conflicts between the UDP port access control when using QGroundControl on the same system as the docker container. :::
:::note If you encounter the error "Can't open display: :0", DISPLAY
may need to be set to a different value. On Linux (XWindow) hosts you can change -e DISPLAY=:0
to -e DISPLAY=$DISPLAY
. On other hosts you might iterate the value of 0
in -e DISPLAY=:0
until the "Can't open display: :0" error goes away. :::
If everything went well you should be in a new bash shell now. Verify if everything works by running, for example, SITL:
The docker run
command can only be used to create a new container. To get back into this container (which will retain your changes) simply do:
If you need multiple shells connected to the container, just open a new shell and execute that last command again.
Sometimes you may need to clear a container altogether. You can do so using its name:
If you can't remember the name, then you can list inactive container ids and then delete them, as shown below:
When running a simulation instance e.g. SITL inside the docker container and controlling it via QGroundControl from the host, the communication link has to be set up manually. The autoconnect feature of QGroundControl does not work here.
:::note Spaces between double curly braces above should be not be present (they are needed to avoid a UI rendering problem in gitbook). :::
The container creates files as needed with a default user - typically "root". This can lead to permission errors where the user on the host computer is not able to access files created by the container.
The example above uses the line --env=LOCAL_USER_ID="$(id -u)"
to create a user in the container with the same UID as the user on the host. This ensures that all files created within the container will be accessible on the host.
It's possible that running Gazebo Classic will result in a similar error message like the following:
In that case the native graphics driver for your host system must be installed. Download the right driver and install it inside the container. For Nvidia drivers the following command should be used (otherwise the installer will see the loaded modules from the host and refuse to proceed):
Any recent Linux distribution should work.
The following configuration is tested:
OS X with VMWare Fusion and Ubuntu 14.04 (Docker container with GUI support on Parallels make the X-Server crash).
Memory
Use at least 4GB memory for the virtual machine.
Compilation problems
If compilation fails with errors like this:
Try disabling parallel builds.
Allow Docker Control from the VM Host
Edit /etc/defaults/docker
and add this line:
You can then control docker from your host OS:
The available containers are on .
The most recent version can be accessed using the latest
tag: px4io/px4-dev-nuttx-focal:latest
(available tags are listed for each container on hub.docker.com. For example, the px4io/px4-dev-nuttx-focal
tags can be found ).
The easiest way to use the containers is via the helper script. This script takes a PX4 build command as an argument (e.g. make tests
). It starts up docker with a recent version (hard coded) of the appropriate container and sensible environment settings.
:::tip The script is easy because you don't need to know anything much about Docker or think about what container to use. However it is not particularly robust! The manual approach discussed in the is more flexible and should be used if you have any problems with the script. :::
In QGroundControl, navigate to and select Comm Links. Create a new link that uses the UDP protocol. The port depends on the used e.g. port 14570 for the SITL config. The IP address is the one of your docker container, usually 172.17.0.1/16 when using the default network. The IP address of the docker container can be found with the following command (assuming the container name is mycontainer
):
More information on this can be found .