Changes
Page history
Update Dockerization
authored
Oct 21, 2022
by
Daniel Kluge
Show whitespace changes
Inline
Side-by-side
follow-up/Dockerization.md
View page @
3fedb4c7
...
@@ -45,6 +45,13 @@ If you still want to use another image you can add `--build-arg MVN_IMAGE=your_i
...
@@ -45,6 +45,13 @@ If you still want to use another image you can add `--build-arg MVN_IMAGE=your_i
**Be sure to always use an image that provides the JRE 11!**
**Be sure to always use an image that provides the JRE 11!**
The JDK is not necessary.
The JDK is not necessary.
```
Dockerfile
ARG
IS_SENSOR
```
In this line we create an empty variable called
`IS_SENSOR`
.
If any value for this variable is set in the build arguments it will install the necessary packages for handling the sensors.
By leaving it empty it will just install the requirements for Java and MQTT.
### Build Stage
### Build Stage
```
Dockerfile
```
Dockerfile
...
@@ -105,12 +112,15 @@ WORKDIR /root/app
...
@@ -105,12 +112,15 @@ WORKDIR /root/app
Again, this sets the current working directory inside the container.
Again, this sets the current working directory inside the container.
```
Dockerfile
```
Dockerfile
RUN
apt-get update
&&
apt-get
install
-y
mosquitto-clients libgpiod2 python3 python3-pip
&&
rm
-rf
/var/lib/apt/lists/
*
RUN
apt-get update
&&
if
[[
-z
"
$IS_SENSOR
"
]]
;
then
apt-get
install
-y
mosquitto-clients
;
else
apt-get
install
-y
mosquitto-clients libgpiod2 python3 python3-pip
build-essential python3-dev gpiod
;
fi
&&
rm
-rf
/var/lib/apt/lists/
*
```
```
Here all necessary dependencies we may use later.
Here all necessary dependencies we may use later.
If the
`IS_SENSOR`
argument is set in the build arguments many Python packages are installed to communicate with GPIO and the sensors.
Else only
`mosquitto-clients`
is installed to communicate with the MQTT broker.
-
`mosquitto-clients`
: used for communication with out mqtt server
-
`mosquitto-clients`
: used for communication with out mqtt server
-
`libgpiod2`
: GPIO library
-
`libgpiod2`
: GPIO library
-
`python3`
&
`python3-pip`
: our sensors use Python scripts, so we need Python too. Pip because we want to install some packages.
-
`python3`
&
`python3-pip`
: our sensors use Python scripts, so we need Python too. Pip because we want to install some packages.
-
`build-essential`
&
`python3-dev`
&
`gpiod`
: when installing some pip-packages some of them require these to build.
```
Dockerfile
```
Dockerfile
COPY
--from=build /root/.m2 /root/.m2
COPY
--from=build /root/.m2 /root/.m2
...
@@ -121,9 +131,9 @@ Here all files we need from the build stage are copied to our container.
...
@@ -121,9 +131,9 @@ Here all files we need from the build stage are copied to our container.
```
Dockerfile
```
Dockerfile
COPY
./docker-scripts/requirements.txt requirements.txt
COPY
./docker-scripts/requirements.txt requirements.txt
RUN
python3
-m
pip
install
-r
requirements.txt
&&
rm
requirements.txt
RUN
if
[[
-z
"
$IS_SENSOR
"
]]
;
then
python3
-m
pip
install
-r
requirements.txt
;
fi
&&
rm
requirements.txt
```
```
Here the Python packages from the
`requirements.txt`
are installed.
Here the Python packages from the
`requirements.txt`
are installed
but only if
`IS_SENSOR`
is set
.
```
Dockerfile
```
Dockerfile
COPY
./docker-scripts/sensors ./sensor-scripts
COPY
./docker-scripts/sensors ./sensor-scripts
...
...
...
...