... | ... | @@ -2,7 +2,7 @@ Dockerizing the project is challenging because of two things: |
|
|
1. the classpath setup done in [start_component.sh](implementation/start_component.sh)
|
|
|
2. the GPIO pins of the Raspberry Pi must be accessible from inside the container for the lights
|
|
|
|
|
|
## Dockerfile walkthrough
|
|
|
## Dockerfile Walkthrough
|
|
|
The Dockerfile is used to build the container.
|
|
|
It holds instructions on which files to copy and commands to run.
|
|
|
|
... | ... | @@ -10,7 +10,7 @@ I chose a multistage approach. |
|
|
This means first in a dedicated container all dependencies get resolved and files compiled.
|
|
|
They are copied to a second container which serves the purpose of the runtime environment.
|
|
|
|
|
|
### Build stage
|
|
|
### Build Stage
|
|
|
|
|
|
```Dockerfile
|
|
|
FROM maven:3-jdk-11-slim as build
|
... | ... | @@ -57,7 +57,7 @@ Here we finally build all our class files. |
|
|
Our build stage is done.
|
|
|
It follows the container definition for our final container.
|
|
|
|
|
|
### Runtime stage
|
|
|
### Runtime Stage
|
|
|
|
|
|
```Dockerfile
|
|
|
FROM openjdk:11-jre
|
... | ... | @@ -89,11 +89,11 @@ This sets the entry point of the container that is executed when the container i |
|
|
The first part of the command exports the `CLASSPATH` that needs to be set to resolve all the used packages inside the Java files.
|
|
|
It would probably be cleaner to use the `ENV` definition in the Dockerfile but setting an environment based on command output is [currently not possible](https://github.com/moby/moby/issues/29110).
|
|
|
|
|
|
## docker-compose.yml walkthrough
|
|
|
## docker-compose.yml Walkthrough
|
|
|
Every line inside the [`docker-compose.sample.yml`](https://gitlab.hrz.tu-chemnitz.de/vws-demo/vws-spielwiese/-/blob/followup/dockerize/basyx.lichterkette/docker-compose.sample.yml) file is commented.
|
|
|
If you want to create a new file for `docker-compose` you can use this sample as a reference.
|
|
|
|
|
|
## Building the container
|
|
|
## Building the Container
|
|
|
|
|
|
To build the container change the working directory to the `basyx.lichterkette` subdirectory of this repository and run the following command:
|
|
|
|
... | ... | @@ -109,8 +109,8 @@ It is also possible to use `docker-compose` to build the container. |
|
|
# docker-compose [-f filename.yml] build
|
|
|
```
|
|
|
|
|
|
## Running the container
|
|
|
### Components without GPIO access
|
|
|
## Running the Container
|
|
|
### Components without GPIO Access
|
|
|
|
|
|
Starting the container for any component that does not need access to the GPIO pins of the Raspberry Pi is straightforward:
|
|
|
|
... | ... | @@ -120,7 +120,7 @@ Starting the container for any component that does not need access to the GPIO p |
|
|
- `-d` detaches the container, if you want to run it in the foreground omit it.
|
|
|
- `-e COMPONENT=registry` sets the environment variable `COMPONENT`. **This determines which component is started, be sure to set it to the correct component!**
|
|
|
|
|
|
#### Stopping the container
|
|
|
#### Stopping the Container
|
|
|
If you run the container in the foreground just press `Ctrl+C`.
|
|
|
If you started it with the `-d` option, a hash is returned on the command line.
|
|
|
You can stop a detached container using:
|
... | ... | @@ -133,7 +133,7 @@ To remove it, run: |
|
|
# docker rm [hash]
|
|
|
```
|
|
|
|
|
|
### Components without GPIO access
|
|
|
### Components with GPIO Access
|
|
|
|
|
|
For the other components, Docker needs access to the system resources of the Raspberry Pi.
|
|
|
The easiest way to do this (and the only one I found working) is to use the following command:
|
... | ... | @@ -148,7 +148,7 @@ The easiest way to do this (and the only one I found working) is to use the foll |
|
|
|
|
|
For how to stop the container see above.
|
|
|
|
|
|
## Using `docker-compose` for multiple containers
|
|
|
## Using `docker-compose` for Multiple Containers
|
|
|
`docker-compose` can be used to set up whole stacks of containers with one configuration file.
|
|
|
The containers inside this stack are called "services".
|
|
|
For every possible component, there is a service already defined inside the [`docker-compose.sample.yml`](https://gitlab.hrz.tu-chemnitz.de/vws-demo/vws-spielwiese/-/blob/followup/dockerize/basyx.lichterkette/docker-compose.sample.yml).
|
... | ... | |