Describe docker compose example

This commit is contained in:
Ollo 2024-12-17 20:58:17 +01:00
parent 037b2ef12c
commit 3ca17eb4cf
3 changed files with 22 additions and 2 deletions

View File

@ -38,3 +38,22 @@ Set the following parameter:
```docker run -t -i --device=/dev/ttyUSB0 -e SERIAL_DEVICE="/dev/ttyUSB0" -e MQTT_SERVER="192.168.x.y" -e MQTT_TOPIC="testtopic/" sha256:``` ```docker run -t -i --device=/dev/ttyUSB0 -e SERIAL_DEVICE="/dev/ttyUSB0" -e MQTT_SERVER="192.168.x.y" -e MQTT_TOPIC="testtopic/" sha256:```
#### Execution via Docker Compose
```
# template docker-compose.yml
services:
python_app:
attach: false
build:
context: .
dockerfile: Dockerfile
environment:
- SERIAL_DEVICE=/dev/ttyUSB0
- MQTT_SERVER=192.168.x.y
- MQTT_TOPIC=testtopic/
devices:
- "/dev/ttyUSB0:/dev/ttyUSB0"
```
build image: **docker-compose up --build**
start with **docker-compose up --detach**

1
mqttclient/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
docker-compose.yml

View File

@ -77,7 +77,7 @@ try:
continue continue
except (serial.SerialException): except (serial.SerialException):
client.publish(mqtt_topic + "exception", "serial reopen") # check which port was really used client.publish(mqtt_topic + "exception", "serial reopen") # check which port was really used
time.sleep(1.0) time.sleep(3.0)
try: try:
line = ser.readline() # read a '\n' terminated line line = ser.readline() # read a '\n' terminated line
@ -149,7 +149,7 @@ try:
else: else:
client.publish(mqtt_topic + "debug", line) # line was invalid and could not be parsed client.publish(mqtt_topic + "debug", line) # line was invalid and could not be parsed
else: else:
time.sleep(0.2) time.sleep(0.5)
except (KeyboardInterrupt, SystemExit): except (KeyboardInterrupt, SystemExit):
print("User aborted service ...") print("User aborted service ...")