Packaging an App as a Docker Image


This section will describe how to:
  1. Package an alwaysAI app in a self-contained docker image.

  2. Run the app as a docker container.

Package Your App

To build the image, you first need to install the app on the device you’d like to run the app on. Run the app configure CLI command to select the target device:

$ aai app configure

Next, run the app install CLI command to build the runtime environment and install the python dependencies and models:

$ aai app install

Build the docker image on the target device:

$ aai app package --tag <image_name>

Run Your App

If you packaged your app on a remote device, run the following command to work directly on the target device:

$ aai app shell --no-container

You should be able to see your image using the docker images command. Your output might look like this:

$ docker images
REPOSITORY       TAG      IMAGE ID      CREATED       SIZE
<image_name>     latest   e45e70a16ca0  1 minute ago  1.33GB

To run the app in a docker container, use the following command on the target device:

$ docker run --network=host --privileged -d -v /dev:/dev <image_name>
  • The --network==host flag tells docker to map the device’s network interfaces into the container. This enables access to the internet and the Streamer from outside the container.

  • The --privileged flag is needed when working with USB devices.

  • The -d flag runs the container detached from the CLI.

  • The -v /dev:/dev flag mounts the devices directory into the container so that cameras and USB devices can be accessed.

To learn more about these options, visit the Docker Run reference page.

Once your app is up and running you can manage it with docker container commands. A couple useful commands are:

  • docker container ls will give a list of all running containers.

  • docker container kill <id> will stop the container of the given ID.

Learn more about these commands at the Docker container reference page.

To access the Streamer, use the device’s hostname or IP address in your development machine’s browser. For example:

http://raspberrypi:5000