How to copy your MAVSDK Python Docker container and edit the files?

  • Hello! I'm new to Dockers, as well as everything about drones basically. I have done everything needed to run the file using MAVSDK Python using your documentation. What I want to try now is do the exact same (using a Docker container) but instead of running the file use another python code to experiment.

    How am I able to copy your container and just replace the .py files for other .py files and begin experimenting with the drone (I use an m500 and a Linux host PC)? Is this the easiest way to do this (using Docker containers)?

    Thank you!

  • Dev Team

    Great to hear you got the tutorial up and running.

    One thing you could do is use the '-v' option of docker run to share a directory between the docker and base image, documentation here:

    You can edit your code on your PC and push to the target in the shared folder to access inside of the Docker

  • You can add a directory from your host machine which has whatever python files you wish to add via adding a src directory path and mapping it to a path in the containers file structure.

    docker run -it --rm -v /host_src_dir_path:/container_dir_path --privileged --net=host <img>:<tag>

    Upon running the docker container, the directory from /host_src_dir_path will be available at /container_dir_path

  • Thank you very much @ryan_meagher
    I just have some basic questions about this you're telling me. Remember I'm new to this 😞

    According to the instructions in this README repository from ModalAI:

    I’ve been able to do everything for the example program to run in the drone, however I’m not sure which is the container’s directory path that I need to add in the command you’re telling me. The directory in my host machine is just the path where the .py files would be right? Also, I haven't build the image (as it says it's optional) because I'm not sure what benefits does that bring. I don't even know if I have to build the image inside the drone or inside my computer.

    Anyway, here are the commands I use to make an SSH connection to the drone and start the terminal.

    (base) ponchoponce95@ponchoponce95-Lenovo-Y50-70:~$ ssh root@
    root@'s password: 
    ~ # docker run -it --rm --privileged --net=host /bin/bash

    So in order to access my .py files in my computer, instead of typing:

    docker run -it --rm --privileged --net=host /bin/bash

    I must type:

    docker run -it --rm -v /Home/Rutinas:/home --privileged --net=host /bin/bash


    Because that last command is telling me that it can't find the .py files that I have inside my Rutinas folder.

  • Dev Team

    First off, thanks @ryan_meagher for the assitance!!!

    @Alfonso-Ponce ,

    Although you can build on a host computer, you need to understand how to build for ARM, so if you aren't comfortable with that it's easier to build on target (on the VOXL). Here's a good overview:

    A docker container is typically a self contained "box", and you can build the files into the container at BUILD time of said container.

    Like @ryan_meagher mentioned, you can also use mounting to 'copy' files into the container at startup, for example, here's the source to the voxl-docker script (used on host computer) to mount files into the container from the current working directory:

    What you have above needs to be updated to valid paths ON THE VOXL. /Home/Rutinas likely doesn't exist on VOXL.... unless you've made a 'Rutinas' diectory

    Here's a defeault /home

    /home # ls
    adb   audio	 camera    input  root	   system
    apps  bluetooth  graphics  radio  sensors 

    You could instead make a new directory put the files you want to mount in /home/root/rutinas

    /home # cd root/
    ~ # ls  voxl-suite-ipk
    ~ # mkdir rutinas
    ~ # cd rutinas/
    ~/rutinas # pwd

    If you mount it like this /home/root/rutinas:/home you will 'overwrite' or hide the default /home in the docker container btw, so the original files will be gone (e.g. all the files copied here...)

    So you want to mount to another place inside the container likely, perhaps:

  • @modaltb
    Thank you very much again. Now I understand much more. The file that was in the repository is just a code that builds the image inside the VOXL even though I run it in my PC. In the beginning I thought that this file had to be run inside the VOXL.

    Ok so I just built the image using that file and everything went well (I understand the image was built inside VOXL). I created a directory just like you mentioned inside the VOXL and I know how to copy my python files to the new directory I created inside the VOXL, until there everything fine. Now, how do I know the containers directory? How do I acces to it? How do I create a new folder in it if I don't know where it is? 😞
    And finally, does it matter where do I mount my files inside the container? If I run the

    python3 udp://:14551

    Will it find it? Or where is that original file inside the container?
    In other words, how do I browse inside the container?

    Thank you! And sorry for all these basic questions.

  • @modaltb Ok so I can see that by looking at the Dockerfile you linked, the directories of the container are listed there, but I still don't know how can I create a new directory inside /home for example.

  • @Alfonso-Ponce
    You surf in the terminal in docker or home like a standard linux terminal. So,
    I think you should check first this for Linux commands and then this for Docker commands.

  • @Voxlady Thank you! In the end I was finally able to understand better how the VOXL shell and the Docker image/container were working together. I was able to mount the volume just like they recommended and I could send my .py files and execute them.

Log in to reply