Add docker-compose documentation authored by Daniel Kluge's avatar Daniel Kluge
TODO
Dockerizing the project is challenging because of two things: Dockerizing the project is challenging because of two things:
1. the classpath setup done in [start_component.sh](implementation/start_component.sh) 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 2. the GPIO pins of the Raspberry Pi must be accessible from inside the container for the lights
...@@ -91,6 +89,10 @@ This sets the entry point of the container that is executed when the container i ...@@ -91,6 +89,10 @@ 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. 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). 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
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: To build the container change the working directory to the `basyx.lichterkette` subdirectory of this repository and run the following command:
...@@ -103,9 +105,8 @@ The tag `basyx-lichterkette` can be anything. ...@@ -103,9 +105,8 @@ The tag `basyx-lichterkette` can be anything.
If you change it, be sure to replace the tag name in any following command in this documentation. If you change it, be sure to replace the tag name in any following command in this documentation.
It is also possible to use `docker-compose` to build the container. It is also possible to use `docker-compose` to build the container.
TODO - docker-compose.yaml
```console ```console
# docker-compose build # docker-compose [-f filename.yml] build
``` ```
## Running the container ## Running the container
...@@ -116,9 +117,22 @@ Starting the container for any component that does not need access to the GPIO p ...@@ -116,9 +117,22 @@ Starting the container for any component that does not need access to the GPIO p
```console ```console
# docker run -d -e COMPONENT=registry basyx-lichterkette # docker run -d -e COMPONENT=registry basyx-lichterkette
``` ```
- `-d` detaches the container, if you want to run it in the foreground omit it - `-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!** - `-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
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:
```console
# docker stop [hash]
```
To remove it, run:
```console
# docker rm [hash]
```
### Components without GPIO access ### Components without GPIO access
For the other components, Docker needs access to the system resources of the Raspberry Pi. For the other components, Docker needs access to the system resources of the Raspberry Pi.
...@@ -132,6 +146,25 @@ The easiest way to do this (and the only one I found working) is to use the foll ...@@ -132,6 +146,25 @@ The easiest way to do this (and the only one I found working) is to use the foll
- `-v "/usr/bin/raspi-gpio:/bin/raspi-gpio"` mounts the `raspi-gpio` executable inside the container. **You have to have `raspi-gpio` installed on the host system!** - `-v "/usr/bin/raspi-gpio:/bin/raspi-gpio"` mounts the `raspi-gpio` executable inside the container. **You have to have `raspi-gpio` installed on the host system!**
- `--privileged` ensures access to host devices (eg. GPIO) - `--privileged` ensures access to host devices (eg. GPIO)
## Using docker-compose for multiple containers For how to stop the container see above.
## 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).
You can use this file to create your own `docker-compose.yml`.
You can start it with:
```console
# docker-compose [-f filename.yml] up -d
```
- `-d` detaches the container, if you want to run it in the foreground omit it.
- `-f filename.yml` is necessary if your config file is not called `docker-compose.yml` or `docker-compose.yaml`. You can omit it otherwise.
You can stop and remove the stack with the following command:
```
# docker-compose down
```
TODO To start or stop only single services defined inside your config you can append the service names to the `up` or `down` commands.
\ No newline at end of file