How to create / update a docker image for a jetson device

In order to build the docker image, you need to have:

A docker image for TX2 would work on Xavier but wouldn’t have the best performance possible, that is why we need several docker image for each architecture (More on this)

1. Install Opencv 3.4.3:

2. Compile Darknet with Opencv 3.4.3:

3. Create the docker image

# Create a docker folder to gather all dependencies
mkdir docker
cd docker

# Copy previously compiled darknet in docker folder
cp -R <pathtodarknet> .

# Download opencv-3.4.3.tar.gz
# This is the pre-installed version of opencv to include in the docker container
# If you compiled Opencv yourself, you'll find how to create the tar file in the section explaning how to compile opencv

# For Jetson Nano:

# For Jetson TX2:

# For Jetson Xavier:

# Download the Dockerfile

# Download a script to include in the docker container

# Build image
sudo docker build -t opendatacam .

# If you are building a second time, use this to pull the latest opendatacam code
# TODO change this by adding the tag of the version in the Dockerfile
# Technique to rebuild the docker file from here :
# Build using date > marker && docker build .
date > marker && sudo docker build -t opendatacam .

4. Try the docker image

# Get the darknet-docker script
wget -N

# Chmod to give exec permissions
chmod 777

# Run image interactively while giving access to CUDA stuff
sudo ./ run --rm -it opendatacam

# Open browser at http://<IP of Jetson>:8080

5. Publish the docker image

# Log into the Docker Hub
sudo docker login --username=opendatacam
# Check the image ID using
sudo docker images
# You will see something like:
# REPOSITORY              TAG       IMAGE ID         CREATED           SIZE
# opendatacam             latest    023ab91c6291     3 minutes ago     1.975 GB

# Tag your image
sudo docker tag <IMAGEID> opendatacam/opendatacam:v3.0.0-beta.1-nano

# Or for tx2 : opendatacam/opendatacam:v3.0.0-beta.1-tx2
# Or for xavier : opendatacam/opendatacam:v3.0.0-beta.1-xavier

# Push image
sudo docker push opendatacam/opendatacam:v3.0.0-beta.1-nano

# (optional) Useful Untag image (if you made a tipo)
sudo docker rmi opendatacam/opendatacam:v3.0.0-beta.1-nano

(Optional) Compile Opencv on jetson (this takes 1-2h)


Need this because darknet needs to be compiled with the same version as the one running inside the docker file

# Optional: put jetson in high performance mode to speed up things
sudo nvpmodel -m 0
sudo jetson_clocks

# For jetson nano, adding a swap partition of 6GB is essential
# Follow this article

# Clone 
# Same repo for xavier or tx2 or nano since jetpack 4.2
# For jetson nano there is missing dependency, here is the fixed repo:
git clone
cd buildOpenCVXavier

# Edit the ARCH_BIN variable
# Set ARCH_BIN=5.3 in for Jetson Nano
# Set ARCH_BIN=6.2 in for Jetson TX2
# Set ARCH_BIN=7.2 in for Jetson Xavier

# Specify the right ARCH_BIN makes runtime faster:

# Then run the build command, on TX2 it takes more than 1 hour

# The binary files will be in ~/opencv/build
cd ~/opencv/build

There is one extra step to do to prepare the opencv-3.4.3.tar.gz file to include in the docker container. The one built before nests a folder inside and we want to remove it

# Create the opencv compiled tar package

# Go to opencv/build
cd ~/opencv/build

# Untar the default OpenCV-3.4.3-aarch64.tar.gz
tar -xvzf OpenCV-3.4.3-aarch64.tar.gz

# Move to directory untar
cd OpenCV-3.4.3-aarch64

# Tar the content in opencv-3.4.3.tar.gz
tar -czvf opencv-3.4.3.tar.gz .

# The result opencv-3.4.3.tar.gz is the archive you need to include in the docker image to install opencv