dht is a Docker image for adafruit-circuitpython-dht, a Python driver for DHT11 and DHT22 temperature-humidity sensors. The docker image is based on python:3.8. The sensor is queried, temperature and humidity are logged to a time-series database using influxdb-python.
This example uses the docker build
command to build the image and the docker run
command to create a container from that image.
docker build --tag dht .
docker run -d dht
This is an example service definition that could be added in docker-compose.yml
. The dht service depends on the influxdb service for data logging.
dht:
container_name: dht
build: ./services/dht/
depends_on:
- influxdb
environment:
- DHT_HOSTNAME=daeron
- DHT_INTERVAL=5
- INFLUXDB_HOST=influxdb
- INFLUXDB_PORT=8086
- INFLUXDB_DB=iot
- INFLUXDB_USER=<insert user>
- INFLUXDB_PASSWORD=<insert password>
- INFLUXDB_RETENTION_POLICY=raw
- INFLUXDB_MEASUREMENT=air
devices:
- /dev/gpiomem:/dev/gpiomem
privileged: true
restart: unless-stopped
influxdb:
container_name: influxdb
image: influxdb:latest
environment:
- INFLUXDB_DB=<insert db>
- INFLUXDB_DATA_ENGINE=tsm1
- INFLUXDB_REPORTING_DISABLED=false
- INFLUXDB_HTTP_AUTH_ENABLED=true
- INFLUXDB_ADMIN_ENABLED=true
- INFLUXDB_ADMIN_USER=admin
- INFLUXDB_ADMIN_PASSWORD=<insert password>
volumes:
- ./volumes/influxdb/data:/var/lib/influxdb
- ./volumes/influxdb/backup:/var/lib/influxdb/backup
ports:
- 8086:8086
- 8083:8083
- 2003:2003
restart: always