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

1 Hardware pre-requisite

In order to build the docker image, you need to build the docker image on the same architecture as the target device that will use the docker image. (ie: build docker image for Jetson Xavier on a Jetson Xavier)

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)

2. Create the docker image

# Go to the opendatacam build directory for you platform (xavier or nano)
# Nano
cd opendatacam/docker/build/nano
# Xavier
cd opendatacam/docker/build/xavier

# Download the weights you want to include ( currently yolov4-tiny for Nano and yolov4 for xavier )
# Nano
# Xavier

# Build
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 .

# Test the image with docker-compose
# nano
cd opendatacam/docker/run/nano
# xavier
cd opendatacam/docker/run/xavier
# copy config.json and edit with the parameters you need
cp ../../../config.json .
# change
# PATH_TO_YOLO_DARKNET=/var/local/darknet
# NEURAL_NETWORK=yolov4 (xavier) | yolov4-tiny (nano)

# Tag the local image
sudo docker tag <IMAGEID> opendatacam/opendatacam:v3.0.1-nano
sudo docker tag <IMAGEID> opendatacam/opendatacam:v3.0.1-xavier
# Spin containers
sudo docker-compose up

3. 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.1-nano

# Or for xavier : opendatacam/opendatacam:v3.0.1-xavier

# Push image
sudo docker push opendatacam/opendatacam:v3.0.1-nano

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

Note about Darknet Makefile differences for docker build


# to


COMMON+= -DGPU -I/usr/local/cuda/include/
# to
COMMON+= -DGPU -I/usr/local/cuda-10.0/include/


LDFLAGS+= -L/usr/local/cuda/lib -lcuda -lcudart -lcublas -lcurand
# to
LDFLAGS+= -L/usr/local/cuda-10.0/lib -lcuda -lcudart -lcublas -lcurand


LDFLAGS+= -L/usr/local/cuda/lib64 -lcuda -lcudart -lcublas -lcurand
# to
LDFLAGS+= -L/usr/local/cuda-10.0/lib64 -lcuda -lcudart -lcublas -lcurand


CFLAGS+= -DCUDNN -I/usr/local/cuda/include
LDFLAGS+= -L/usr/local/cuda/lib -lcudnn
# to
CFLAGS+= -DCUDNN -I/usr/local/cuda-10.0/include
LDFLAGS+= -L/usr/local/cuda-10.0/lib -lcudnn


CFLAGS+= -DCUDNN -I/usr/local/cudnn/include
LDFLAGS+= -L/usr/local/cudnn/lib64 -lcudnn
# to
CFLAGS+= -DCUDNN -I/usr/local/cuda-10.0/include
LDFLAGS+= -L/usr/local/cuda-10.0/lib64 -lcudnn