Copyright (C) 2021, Axis Communications AB, Lund, Sweden. All Rights Reserved.
This example demonstrates how to create a simple containerized Python application and run it on an edge device.
Going from zero to a Python application running on an Axis device is quite easy. First, the application script is written, as in the hello-world script in app/simply_hello.py. Next, the Dockerfile which builds the application image is constructed. The application needs to be built and uploaded, as is specified below.
Following are the list of files and a brief description of each file in the example
hello-world-python
├── app
│ └── simply_hello.py
├── Dockerfile
├── docker-compose.yml
└── README.md
- simply_hello.py - A Python script that prints "Hello World"
- Dockerfile - Build instructions for the application image that is run on the camera
- docker-compose.yml - A docker-compose file that specifies how the application is run
Meet the following requirements to ensure compatibility with the example:
- Axis device
- Chip: ARTPEC-8 DLPU devices (e.g., Q1656)
- Firmware: 11.10 or higher
- Docker ACAP version 3.0 installed and started, using TLS with TCP and IPC socket and SD card as storage
- Computer
- Either Docker Desktop version 4.11.1 or higher,
- or Docker Engine version 20.10.17 or higher with BuildKit enabled using Docker Compose version 1.29.2 or higher
Define and export the application image name in APP_NAME
for use in the Docker Compose file.
export APP_NAME=hello-world-python
# Install qemu to allow build for a different architecture
docker run --rm --privileged multiarch/qemu-user-static --credential yes --persistent yes
docker build --tag $APP_NAME .
DEVICE_IP=<actual camera IP address>
DOCKER_PORT=2376
docker --tlsverify --host tcp://$DEVICE_IP:$DOCKER_PORT system prune --all --force
If you encounter any TLS related issues, please see the TLS setup chapter regarding the DOCKER_CERT_PATH
environment variable in the Docker ACAP repository.
Browse to the application page of the Axis device:
http://<AXIS_DEVICE_IP>/index.html#apps
Click on the tab Apps
in the device GUI and enable Allow unsigned apps
toggle.
Next, the built image needs to be uploaded to the device. This can be done through a registry or directly. In this case, the direct transfer is used by piping the compressed application directly to the device's Docker client:
docker save $APP_NAME | docker --tlsverify --host tcp://$DEVICE_IP:$DOCKER_PORT load
With the application image on the device, it can be started using docker-compose.yml
:
docker --tlsverify --host tcp://$DEVICE_IP:$DOCKER_PORT compose up
# Cleanup
docker --tlsverify --host tcp://$DEVICE_IP:$DOCKER_PORT compose down
The expected output from the application is simply:
Hello World!