Gazebo Robot Simulator in a Docker Container

Well this is one of my first attempts at working with a docker container in order to isolate various AUR packages and perform patches or version control on dependencies, without interfering with package dependencies on my primary system. Up until this point, I have worked with various virutal python environments when experimenting with AI tools obtained from Github. Docker containers offer virtual environment advantages for software which is not necessarily utilizing python based applications. Therefore, it is a nice technology to familiarize myself with for future experiments.

#!/bin/bash
echo "Script for creating a docker container with X server forwarding enabled"
docker run -it \
  --gpus all \
  -e DISPLAY=$DISPLAY \
  -v /tmp/.X11-unix:/tmp/.X11-unix \
  --network host \
  --user root \
  --hostname sparkdockergazebo \
  --name arch_for_gazebo \
  archlinux:latest \
  /bin/bash

The above is a bash shell script for creating a docker container (persistent) which should allow X server forwarding.

Update:

Gazebo turned out to be not exactly what I was looking for in terms of learning how to use FANUC robotics for industrial work cell operation. Instead, I settled on RoboDK, as it was somewhat easier to use and had the FANUC automotive arm robots already available in the robotics asset library. Additionally, the interface seemed nicer and they offered a 30-day free trial.

The software was set up in an ubuntu image inside a docker container, which was interesting to set up. Here are some of the bash shell scripts which were created to facilitate this:

#!/bin/bash
echo "Script for creating a docker container with X server forwarding enabled, admin user setup, hostname fix, volume mount, and root password change"
echo "This script uses a Dockerfile instead of passing an initial long string argument to the starting bash command, which should allow it to be more reusable"

# Check if the image already exists
if [[ "$(docker images -q ubuntu_for_robodk 2> /dev/null)" == "" ]]; then
  echo "Image does not exist. Building now..."
  # Build the Docker image
  docker build -t ubuntu_for_robodk .
else
  echo "Image already exists. Skipping build step."
fi

# Check if the container already exists
if [[ "$(docker ps -aq -f name=ubuntu_for_robodk)" ]]; then
  echo "Container already exists. Starting and attaching to it..."
  docker start -i ubuntu_for_robodk
else
  echo "Creating and starting new container..."
  # Create and start the container
  docker run -it \
    --gpus all \
    -e DISPLAY=$DISPLAY \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -v /home/sparkone/Downloads:/mnt/host \
    --network host \
    --hostname sparkdockerrobodk \
    --name ubuntu_for_robodk \
    ubuntu_for_robodk
fi
[sparkone@sparktwo Docker]$ cat start_container_ubuntu_x11forward_0.sh 
#!/bin/bash

# Name of your Docker container
CONTAINER_NAME="ubuntu_for_robodk"

# Check if the container exists
if ! docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
    echo "Container ${CONTAINER_NAME} does not exist. Please create it first."
    exit 1
fi

# Check if the container is running
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
    echo "Container ${CONTAINER_NAME} is not running. Starting it now..."
    docker start ${CONTAINER_NAME}
fi

# Attach to the container
echo "Attaching to container ${CONTAINER_NAME}..."
docker exec -it ${CONTAINER_NAME} /bin/bash

echo "Exited from container ${CONTAINER_NAME}"
#!/bin/bash
echo "Script for creating a docker container with X server forwarding enabled, admin user setup, hostname fix, volume mount, and root password change"
echo "This script uses a Dockerfile instead of passing an initial long string argument to the starting bash command, which should allow it to be more reusable"

# Check if the image already exists
if [[ "$(docker images -q ubuntu_for_robodk 2> /dev/null)" == "" ]]; then
  echo "Image does not exist. Building now..."
  # Build the Docker image
  docker build -t ubuntu_for_robodk .
else
  echo "Image already exists. Skipping build step."
fi

# Check if the container already exists
if [[ "$(docker ps -aq -f name=ubuntu_for_robodk)" ]]; then
  echo "Container already exists. Starting and attaching to it..."
  docker start -i ubuntu_for_robodk
else
  echo "Creating and starting new container..."
  # Create and start the container
  docker run -it \
    --gpus all \
    -e DISPLAY=$DISPLAY \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -v /home/sparkone/Downloads:/mnt/host \
    --network host \
    --hostname sparkdockerrobodk \
    --name ubuntu_for_robodk \
    ubuntu_for_robodk
fi

Leave a Reply

Your email address will not be published. Required fields are marked *