|
| 1 | +# Running semonitor in docker |
| 2 | +SEMonitor can be run within a Docker container. This provides isolation from |
| 3 | +other processes by running it in a containerized environment. As this is not |
| 4 | +and in-depth tutorial on docker, those with Docker, containers or cgroups see |
| 5 | +[docker.com][docker]. |
| 6 | + |
| 7 | +This guide is not a comprehensive guide, but just lists the most basic things! |
| 8 | + |
| 9 | + |
| 10 | +## Building the container |
| 11 | +Building the container is only needed if the official one is not sufficient, |
| 12 | +or when developing on semonitor. |
| 13 | + |
| 14 | +To build the image, the following can be used, where `ISSUE-123` is just used |
| 15 | +as an example. It is important in that it will be re-used later. |
| 16 | + |
| 17 | +```sh |
| 18 | +docker image build \ |
| 19 | + --file 'Containerfile' \ |
| 20 | + --rm \ |
| 21 | + --tag 'semonitor:ISSUE-123' \ |
| 22 | + './' |
| 23 | +``` |
| 24 | + |
| 25 | + |
| 26 | +## Running tests |
| 27 | +The tests are not included in the container image, so we volume mount them to |
| 28 | +make them available to the installed semonitor application. |
| 29 | + |
| 30 | +```sh |
| 31 | +docker container run \ |
| 32 | + --interactive \ |
| 33 | + --rm \ |
| 34 | + --tty \ |
| 35 | + --user 'root:root' \ |
| 36 | + --volume "$(pwd)/test:/usr/local/src/semonitor/test" \ |
| 37 | + 'semonitor:ISSUE-123' \ |
| 38 | + '/bin/sh' -c 'runuser --user semonitor -- ./test/test.sh' |
| 39 | +``` |
| 40 | + |
| 41 | + |
| 42 | +## Running serial device |
| 43 | +Running the semonitor on a serial device using the official latest image can |
| 44 | +be done as follows. |
| 45 | + |
| 46 | +```sh |
| 47 | +docker container run \ |
| 48 | + --device '/dev/solaredge0:/dev/ttyUSB0' \ |
| 49 | + --interactive \ |
| 50 | + --rm \ |
| 51 | + --tty \ |
| 52 | + --volume "$(pwd)/semonitor_logs/:/semonitor/" \ |
| 53 | + 'ghcr.io/jbuehl/solaredge:latest' \ |
| 54 | + semonitor.sh \ |
| 55 | + -a \ |
| 56 | + -b 115200 \ |
| 57 | + -m \ |
| 58 | + -o "/semonitor/json/$(date +%Y%m%d).json" \ |
| 59 | + -r "/semonitor/rec/$(date +%Y%m%d).rec" \ |
| 60 | + -s '1234567' \ |
| 61 | + -t 4 \ |
| 62 | + '/dev/ttyUSB0' |
| 63 | +``` |
| 64 | + |
| 65 | +## Using compose |
| 66 | +It is also possible to run the container using `docker compose`. Here an |
| 67 | +example. The device used is a udev symlinked serial to USB adapter, whith |
| 68 | +the appropriate permissions. |
| 69 | + |
| 70 | +```yaml |
| 71 | +networks: |
| 72 | + semonitor: {} |
| 73 | + |
| 74 | +volumes: |
| 75 | + semonitor: |
| 76 | + |
| 77 | +services: |
| 78 | + sslh: |
| 79 | + image: ghcr.io/jbuehl/solaredge:master |
| 80 | + cap_drop: |
| 81 | + - all |
| 82 | + ulimits: |
| 83 | + nproc: 64 |
| 84 | + nofile: |
| 85 | + soft: 4194304 |
| 86 | + hard: 16777216 |
| 87 | + devices: |
| 88 | + - /dev/solaredge:/dev/ttyUSB0 |
| 89 | + env_file: |
| 90 | + - common.env |
| 91 | + volumes: |
| 92 | + - semonitor:/var/lib/semonitor:rw |
| 93 | + networks: |
| 94 | + - semonitor |
| 95 | + expose: |
| 96 | + - "80/tcp" |
| 97 | + - "22221-22222/tcp" |
| 98 | + command: -a -b 115200 -m -o "/var/lib/semonitor/json/__date__.json" -r "/var/lib/semonitor/rec/__date__.rec" -s '1234567' -t 4 '/dev/ttyUSB0' |
| 99 | + restart: unless-stopped |
| 100 | +``` |
0 commit comments