Docker¶
Instead of setting up a server and uWSGI manually, a device can also be deployed with docker. The image is self-contained, it bundles nginx, uWSGI and supervisord, so none of the prerequisites described for the bare-metal setup are needed.
Note
No pre-built image is published for devices, since a device’s implementation (the hardware communication
you write) is always specific to your project. You build your own image from the `Dockerfile` provided
by the skeleton at `pkg/docker/Dockerfile`.
Build the Image¶
Install docker on your system, then, from the top level directory of your device source, build the image:
docker build -f pkg/docker/Dockerfile -t <YOUR_DEVICE_NAME>:latest .
Docker Compose¶
A simple docker configuration may look like this docker-compose.yml:
services:
muscle-device:
image: <YOUR_DEVICE_NAME>:latest
build:
dockerfile: pkg/docker/Dockerfile
context: .
container_name: muscle-device
restart: always
# pass hardware interfaces through to the container, e.g. a serial device
# devices:
# - /dev/ttyUSB0:/dev/ttyUSB0
ports:
- 0.0.0.0:8088:8088
The device API is exposed on port 8088 inside the container.
Note
If your hardware is connected via a physical interface (serial, USB, …), uncomment and adjust the
devices section to pass it through to the container.
Configuration¶
The image already ships with sane defaults, logging to the container’s standard output/error
(LOG_PATH=/dev, DEVICE_LOG_FILE=stdout, ACCESS_LOG_FILE=stdout, see
Logging). Any of the configuration parameters
can be set as environment variables in the compose file, the same way as for the
application’s docker image:
services:
muscle-device:
#...
environment:
- AUTHENTICATION_BACKEND=https://backend.my-muscle.com
Starting the Container¶
docker-compose up -d