If you've problem in running the GUI Applications in the Container try the following methods:
Make sure that output of env | grep DISPLAY should contain 1 line and should look like this: DISPLAY=:1. If not then, manually feed the DISPLAY value in the run command. For example sudo docker run -d -it --rm -v ~/Docker/Shared-Volumes/ariitk-Container:/home/Shared-Volume/ -v /tmp/.X11-unix/:/tmp/.X11-unix --net host --env="DISPLAY=:1" --name ariitk <image_name/image_id>
If error = libGL error: MESA-LOADER: failed to retrieve device information. Add this parameter this in docker run : -e LIBGL_ALWAYS_SOFTWARE=1 and install the required libraries.
Note: We've provided --rm argument, so do all the work in the shared directory. Because all the data outside shared directory would be deleted as soon as the container is stopped. And in order to save any changes in the docker container, use docker commit to create a new version for the changes
Attach to Docker Container
Shell used: bash
docker exec -it ariitk /bin/bash
Initial Setup Inside the Container
Copy .bashrc of root user to ariitk user
Copy /root/.ardupilot_env to /user/ariitk/.ardupilot_env
Append export PATH=$PATH:/root/.local/bin/ to root user's .bashrc
MAVROS Setup
mkdir -p ardupilot_ws/src
cd ardupilot_ws/
catkin init
cd src/
mkdir launch
roscp mavros apm.launch apm.launch
After this, edit apm.launch such that it uses a Network Port instead of Physical Port
To test the Successful Setup of Docker Container, run the following commands in different Terminals (in order)
roscore
gazebo --verbose ~/ardupilot_gazebo/worlds/iris_arducopter_runway.world
sim_vehicle.py -v ArduCopter -f gazebo-iris --console --map --out=tcpin:127.0.0.1:2626 # It should be run as root and the Network Address in --out should be the same that was edited in apm.launch
roslaunch apm.launch
You should see a Drone in the Middle of a Runway.
To Test MAVROS and MAVPROXY. You can ARM the drone.
List the ROS Topics and Services with the following commands.
rostopic list
rosservice list
ARM the Drone with the Following Service Call
rosservice call /mavros/cmd/arming true
Save the Initial Changes
To save the Initial Changes make an image of the container
docker commit ariitk ariitk/ardupilot
Export Docker Image
To export a docker Image, type the following command
docker save -o <filename>.tar ariitk/ardupilot
Using Docker Image
Import Docker Image
To import a docker image, type the following command
docker load -i <filename>.tar
You can then tag the import image with the following command
docker tag <image_id> my_custom_image:latest
You can find the image_id with the following command
docker image list
Make a Shared Directory between Host & Docker Container
If you've problem in running the GUI Applications in the Container try the following methods:
Make sure that output of env | grep DISPLAY should contain 1 line and should look like this: DISPLAY=:1. If not then, manually feed the DISPLAY value in the run command. For example sudo docker run -d -it --rm -v ~/Docker/Shared-Volumes/ariitk-Container:/home/Shared-Volume/ -v /tmp/.X11-unix/:/tmp/.X11-unix --net host --env="DISPLAY=:1" --name ariitk <image_name/image_id>
If error = libGL error: MESA-LOADER: failed to retrieve device information. Add this parameter this in docker run : -e LIBGL_ALWAYS_SOFTWARE=1 and install the required libraries.
Note: We've provided --rm argument, so do all the work in the shared directory. Because all the data outside shared directory would be deleted as soon as the container is stopped. And in order to save any changes in the docker container, use docker commit to create a new version for the changes