Connecting QGroundcontrol to PX4 SITL Running inside Docker

Hi. I am running PX4 SITL inside a docker container. I would like to use QGroundControl outside the docker container (running on host) but I am not able to do that so far. I followed instruction in (https://dev.px4.io/v1.10/en/test_and_ci/docker.html#qgroundcontrol):

  • I used p 14570:14570/udp with the run docker command to expose/forward 14570 port
  • Created comm link in QGC with 14570 port and the docker container IP address.

However, when I try to connect to this link, QGC gives a message that the bounding address is already in use!
But I don’t think that this address is being used. What could be the issue?

Thanks!

2 Likes

Try https://github.com/jonasvautherin/px4-gazebo-headless

1 Like

Did you get any fix for this? I am in a similar scenario where I want to connect a PX4 SITL running in a docker with Airsim and QGroundControl

I ended up running QGC inside the container.

@beekay @Mzahana If you forward the mavlink to 14550 (which is the default QGC listens to), it should just work

@Jaeyoung-Lim I currently have the same issue. I’m fairly new to all this, could you provide the steps to forward it? Would this be done in QGC or the docker config?

@mhoang You should try what I suggested in my previous response, to forward the UDP port QGC listens to.

You can go through Networking in Compose | Docker Docs if you are not sure what to do

@mhoang @Mzahana, you should check your ${FIRMWARE_DIR}/build/px4_sitl_default/etc/init.d-posix/px4-rc.mavlink folder. There you can find the udp_gcs_port_local. That is the value you should be specifying in QGroundControl. The tutorial incorrectly assumes 14570 for everyone, or it has been deprecated.

2 Likes

Wow~ Thanks @tahsinkose
Finally I found the setting values:
Type: UDP
Port: 18550
Server Address: 172.17.0.2:18570

In docker run command, port forwarding option is as below:
-p 18570:18570/udp

I found the port number 18570 as your method, but that port number 18550 is just guessed by my thought. So I don’t know why it is 18550.

Hi @Jaeyoung-Lim , some update on the document below seems to be needed using this solution because it does not work for QGC connection:
https://dev.px4.io/v1.11_noredirect/en/test_and_ci/docker.html

Environment:
PX4 SITL inside a docker container by px4io/px4-dev-ros-melodic image
QGC(QGroundControl) outside of the container
Ubuntu 18.04
PX4 v1.14.0beta
QGC v4.2.4

1 Like

Hi @bigbellmercy
I would like to ask you for help. I have exactly the same situation. I am running the PX4 from docker using -p 18570:18570/udp. And then I go to Qgroundcontrol sw and I create new Comm Link with setup as:
udp
port - 18550
server (optional) - 172.17.0.2:18570
But still even if I click to connect I see Disconnected in the main QGC window. I absolutly dont know what can be wrong here. Can you help, did I miss any step?

Hey Lucas, here are some check points:

  1. Have you succeeded in connecting PX4 SITL and QGC by UDP when Docker is not used.

  2. On the terminal of PX4 SITL there are many log lines which include IP addresses and ports related those setting.

Hi @bigbellmercy ,
I have noticed of those messages during simulation start, when there are ports mentioned. And After hours of tunning I have finally connected to the drone from docker :slight_smile: The trick was in proper port number 18570 (thanks to your post) and using localhost IP address 0.0.0.0 with proper port pinted in docker image.
So finally it is working. Thank you for interest and for your post, it was very big hint :slight_smile:

1 Like

Hi @Lukas,
I’m running into the exact same issue but I still cannot find a way to connect from QGC to the simulation running in the docker container. As far as I can tell I have tried all of the suggestions mentioned in this comments.
Could you please tell me what steps to follow?
Is the script provided here correct or should I manually publish some ports?
What ip address and port should I enter in QGC and where can I find them?

Thank you very much for your help :grinning:

hi @gamberoillecito, sure.
I dont use those docker files from here PX4 Docker Containers | PX4 User Guide. I use my own docker file instead, but from that description I can say the port is wrong, in default it is exposed on 18570.
So when I use my own docker image I expsoe this port in taht image and it is set on 0.0.0.0 IP as default.
So in QGC you need to go to commlinks, create a new one and say the QGC shall listen on 18571 (port: filed) and in server (optional) field you need to specify the ip and exposed port, so it needs to say 0.0.0.0:18570. And you shall be able to communicate with the drone.
If yo uwant to use the docker command from documentation, I would suggest to try to expose this other port, not the one mentioned in example.

Hi @Lukas, I’ve been trying to configure the exposed ports according to what you said but I haven’t yet been able to connect to QGC Daily.
When creating the container I ran it with the following code:
docker run --name arucosim_2 -p 18570:18570/udp -it tracking bash
And when I ran docker ps, I got this as the output:
arucosim_question1

In QGC Daily, I created the Comm Link with the following settings:

But when I try running the simulation in PX4 (make px4_sitl gz_x500_mono_cam_down_aruco), I get this as the output:

Let me see if I can help as I’ve done this many times with Docker, but struggled for months to figure it out. Inside my Docker container I have PX4 cloned and am testing with a world I’m working on for April Tag detection. It’s based on the aruco world you’re testing with. If you read the comment here:

You’ll see that broadcasting doesn’t work in a VM. Right now I’m running Docker on Mac but I think the same should apply if you’re on Windows.

Open a terminal in your Docker container and run the following command:

echo “$(getent hosts host.docker.internal | awk ‘{ print $1 }’)”

In my case this prints:

192.168.65.254

Then edit the following file. You’ll likely need to build first so that this file exists:

vi build/px4_sitl_default/etc/init.d-posix/px4-rc.mavlink

on Line 14 you should add that internal IP like this:

mavlink start -x -u $udp_gcs_port_local -r 4000000 -f -t 192.168.65.254

It’s right beneath the “GCS Link” comment. Here is a screenshot:

Now run your make px4_sitl gz_x500_mono_cam_down_aruco

and fire up QGC on the host. It should automatically connect. I hope this helps and I realize it’s not the cleanest solution, but it does work for me. Feel free to follow up with any questions.