Skip to content
Kiriti Gowda edited this page Aug 31, 2023 · 7 revisions

  • Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers.
  • Containers are isolated from one another and bundle their own software, libraries, and configuration files; they can communicate with each other through well-defined channels.
  • All containers are run by a single operating system kernel and therefore use fewer resources than virtual machines.
  • The software that hosts the containers is called Docker Engine.

READ MORE

MIVisionX Docker

Docker Workflow on Ubuntu 20.04/22.04

Prerequisites

Workflow

  • Step 1 - Get latest docker image

    sudo docker pull mivisionx/ubuntu-20.04:latest
    
  • Step 2 - Run docker image

Run docker image: Local Machine

sudo docker run -it --privileged --device=/dev/kfd --device=/dev/dri --device=/dev/mem --cap-add=SYS_RAWIO  --group-add video --shm-size=4g --ipc="host" --network=host mivisionx/ubuntu-20.04:latest
  • Test - Computer Vision Workflow
    python3 /workspace/MIVisionX/tests/vision_tests/runVisionTests.py --num_frames 1
    
  • Test - Neural Network Workflow
    python3 /workspace/MIVisionX/tests/neural_network_tests/runNeuralNetworkTests.py --profiler_level 1
    
  • Test - Khronos OpenVX 1.3.0 Conformance Test
    python3 /workspace/MIVisionX/tests/conformance_tests/runConformanceTests.py --backend_type HOST
    
    • NOTE: run --backend_type HOST/HIP/OCL/ALL

Option 1: Map localhost directory on the docker image

  • option to map the localhost directory with data to be accessed on the docker image
  • usage: -v {LOCAL_HOST_DIRECTORY_PATH}:{DOCKER_DIRECTORY_PATH}
    sudo docker run -it -v /home/:/root/hostDrive/ -privileged --device=/dev/kfd --device=/dev/dri --device=/dev/mem --cap-add=SYS_RAWIO  --group-add video --shm-size=4g --ipc="host" --network=host mivisionx/ubuntu-20.04:latest
    

Option 2: Display with docker

  • Using host display for docker

    xhost +local:root
    sudo docker run -it --privileged --device=/dev/kfd --device=/dev/dri --cap-add=SYS_RAWIO --device=/dev/mem --group-add video --network host --env DISPLAY=$DISPLAY --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --volume /tmp/.X11-unix/:/tmp/.X11-unix mivisionx/ubuntu-20.04:latest
    
  • Test display with MIVisionX sample

    runvx -v /opt/rocm/share/mivisionx/samples/gdf/canny.gdf
    

Run docker image with display: Remote Server Machine

sudo docker run -it --privileged --device=/dev/kfd --device=/dev/dri --cap-add=SYS_RAWIO --device=/dev/mem --group-add video --network host --env DISPLAY=$DISPLAY --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --volume /tmp/.X11-unix/:/tmp/.X11-unix mivisionx/ubuntu-20.04:latest
  • Test display with MIVisionX sample
    runvx -v /opt/rocm/share/mivisionx/samples/gdf/canny.gdf
    

Run docker image with display: Port Forwarded Remote Server Machine

  • Step 1 - Launch Docker on a remote server in the Terminal 1

    sudo docker run -it --privileged --device=/dev/kfd --device=/dev/dri --cap-add=SYS_RAWIO --device=/dev/mem --group-add video --network host --env DISPLAY=$DISPLAY --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --volume /tmp/.X11-unix/:/tmp/.X11-unix mivisionx/ubuntu-20.04:latest
    
  • Step 2 - Start ssh service in Terminal 1 within the launched Docker

    sudo service ssh start
    
  • Step 3 - Connect to the remote server with Terminal 2 with -X option

  • Step 4 - Login to the Docker launched on the remote server on Terminal 2

    ssh -X root@localhost -p 23
    

    NOTE: password - root

  • Step 5 - Test X-11 port forwarding

    runvx /opt/rocm/share/mivisionx/samples/gdf/canny.gdf
    

Creating a docker image - Ubuntu 18.04 Base

Prerequisites

Steps to create a docker image

Step 1: Starting from an Ubuntu Image

  • Pull offical ubuntu docker from docker hub.
sudo docker pull ubuntu:18.04
  • Ubuntu docker hub repo has many versions available, use the image and tag which is required.

Step 2: Run the docker image

sudo docker run -it {USER_OPTIONS} --group-add video --network host ubuntu:18.04
  • Running the docker image with different user options, lets docker access different resources.

  • Review the user options using the following commands

 man docker
  • --groups-add video - adds you to the video group, --network host - allows you to access host network

Step 3: Install software or make changes to your docker image

  • Now you can change the docker image from within to include the software or changes to the settings

  • Inside the docker, use it as a normal ubuntu machine terminal

Step 4: Save changes on the docker

  • Open another terminal on the host machine

  • Check which docker images are currently in use, the below commands lists all docker in use

sudo docker ps
  • Now select the docker your are working on by noting the container id

  • Commit your changes to your docker

sudo docker commit {container_id} {dockerhub_username}/{docker_name_you_want}:{tag}

Step 5: Push docker image to your docker hub

sudo docker push {dockerhub_username}/{docker_name_you_want}:{tag}
  • Now the docker image is available on docker hub.

  • Check in help can be found using the following command

docker push --help

MIVisionX Dockers

Use pre-built dockers from MIVisionX

Camera with docker

sudo docker run -it 
-v /home/:/root/hostDrive/ 
-v /dev/video0:/dev/video0 
-v /tmp/.X11-unix:/tmp/.X11-unix 
--volume="$HOME/.Xauthority:/root/.Xauthority:rw" 
-e "PACKAGES=ffmpeg" 
-e DISPLAY=$DISPLAY  
-e DISPLAY  
--device=/dev/kfd 
--device=/dev/dri 
--device=/dev/mem 
--device /dev/video0 
--device /dev/snd 
--cap-add=SYS_RAWIO 
--group-add video 
--network host 
--env="DISPLAY" 
kiritigowda/ubuntu-18.04:mivisionx

Secure Work Space with Docker

Step 1 - Creating a Docker without ROOT access

  • Sample Docker Creation File - ubuntu18.dockerfile
FROM ubuntu:18.04

RUN apt-get update -y && apt-get install -y sudo
RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo

USER docker
CMD /bin/bash
  • Create the Docker on the local machine
sudo docker build -f ubuntu18.dockerfile -t ubuntu18 .

LOG

Sending build context to Docker daemon  2.048kB
Step 1/5 : FROM ubuntu:18.04
 ---> c090eaba6b94
Step 2/5 : RUN apt-get update -y && apt-get install -y sudo
 ---> Using cache
 ---> 87f007e94c43
Step 3/5 : RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo
 ---> Using cache
 ---> a60979c76100
Step 4/5 : USER docker
 ---> Using cache
 ---> 881368b8111c
Step 5/5 : CMD /bin/bash
 ---> Using cache
 ---> 57114670a637
Successfully built 57114670a637
Successfully tagged ubuntu18:latest
  • Check for the successful creation
sudo docker images

LOG

REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
ubuntu18                   latest              57114670a637        2 minutes ago       101MB

Step 2 - Log in to the Ubuntu18 container

sudo docker run -it --device=/dev/kfd --device=/dev/dri --cap-add=SYS_RAWIO --device=/dev/mem --group-add video --network host --env DISPLAY=unix$DISPLAY --privileged --volume $XAUTH:/root/.Xauthority --volume /tmp/.X11-unix/:/tmp/.X11-unix ubuntu18:latest

Note: logged in to the docker as user:docker password:docker

Step 3 - Create a secret user with a strong password and sudo access

sudo adduser USERNAME
sudo usermod -aG sudo USERNAME

Step 4: Log in as the new user

su USERNAME

Step 5 - Install software to Setup Your Encrypted Private Directory with ecryptfs-utils & Create a private directory

sudo apt-get install ecryptfs-utils 
cd && ecryptfs-setup-private 

LOG

Enter your login passphrase [simon]: 
Enter your mount passphrase [leave blank to generate one]: 

************************************************************************
YOU SHOULD RECORD YOUR MOUNT PASSPHRASE AND STORE IT IN A SAFE LOCATION.
  ecryptfs-unwrap-passphrase ~/.ecryptfs/wrapped-passphrase
THIS WILL BE REQUIRED IF YOU NEED TO RECOVER YOUR DATA AT A LATER TIME.
************************************************************************


Done configuring.

Testing mount/write/umount/read...
Inserted auth tok with sig [29ff2493ee291577] into the user session keyring
Inserted auth tok with sig [a40134a4923e7779] into the user session keyring
Inserted auth tok with sig [29ff2493ee291577] into the user session keyring
Inserted auth tok with sig [a40134a4923e7779] into the user session keyring
Testing succeeded.

Logout, and log back in to begin using your encrypted directory.

Note:

  • Get more info about creation from the man page
  • Any data stored in the folder Private is only accessible by the secret user
  • Now flow the regular docker workflow