Bläddra i källkod

Update to slim docker image (#163)

* Update Dockerfile

Update Docker build

* Upgrade Docker image

* Update Readme.md for Docker change

Add command to purge build images

* Correct Path in docker file

* Revert "Update Readme.md for Docker change"

This reverts commit ec59903f7a4c0a0a083fb071e45f220043d61b30.

* Add Prune instruction to readme

* Update README.md

* Update README.md

Co-authored-by: Thomas Dietrich <Thomas@Nurzen.de>
The-Jeffski 3 år sedan
förälder
incheckning
538b0eb2bd
2 ändrade filer med 24 tillägg och 12 borttagningar
  1. 18 12
      Dockerfile
  2. 6 0
      README.md

+ 18 - 12
Dockerfile

@@ -1,15 +1,21 @@
-FROM python:3-stretch
-MAINTAINER Lars von Wedel <vonwedel@me.com>
+##Miflora-mqtt-daemon  Docker image
+#Builds compact image to run as an alternative to installing the modules/service.  
 
-RUN mkdir -p /usr/src/app
-WORKDIR /usr/src/app
+# The build image
+FROM python:3.10.7-slim as builder
+LABEL stage=builder
+RUN apt-get update && apt-get install bluez gcc libglib2.0-dev build-essential -y && apt-get clean
+COPY requirements.txt /app/requirements.txt
+WORKDIR /app/
+RUN pip install --user -r requirements.txt
+COPY . /app
 
-RUN apt-get update && apt-get install -y bluez
+# The production image
+FROM python:3.10.7-slim as app
+RUN apt-get update && apt-get install bluetooth bluez -y && apt-get clean
+COPY --from=builder /root/.local /root/.local
+COPY --from=builder /app/miflora-mqtt-daemon.py /app/miflora-mqtt-daemon.py
+WORKDIR /app/
+ENV PATH=/root/.local/bin:$PATH
 
-COPY requirements.txt requirements.txt
-RUN pip install --upgrade pip
-RUN pip install --no-cache-dir -r requirements.txt
-
-COPY . .
-
-CMD [ "python3", "./miflora-mqtt-daemon.py", "--config_dir", "/config" ]
+CMD [ "python3", "./miflora-mqtt-daemon.py", "--config_dir", "/config" ]

+ 6 - 0
README.md

@@ -169,6 +169,12 @@ docker run -d --name miflora-mqtt-daemon -v .:/config miflora-mqtt-daemon
 The `/config` volume can be used to provide a directory on the host which contains your `config.ini` file (e.g. the `.` in the above example could represent `/opt/miflora-mqtt-daemon`).
 You may need to tweak the network settings (e.g. `--network host`) for Docker depending on how your system is set up.
 
+It can be worth deleting any redundant images after building a new image:
+
+```shell
+docker image prune 
+```
+
 ## Integration
 
 In the "mqtt-json" reporting mode, data will be published to the MQTT broker topic "`miflora/sensorname`" (e.g. `miflora/petunia`).