Update Dockerization authored by Daniel Kluge's avatar Daniel Kluge
......@@ -3,7 +3,7 @@ Dockerizing the project is challenging because of two things:
2. the GPIO pins of the Raspberry Pi must be accessible from inside the container for the lights
## Prior consideration: Network
Docker and docker-compose make setting up a container stack really easy.
Docker and `docker compose` make setting up a container stack really easy.
But there is a huge drawback: mDNS resolution won't work from inside a container.
But as components like lights register their address as `hostname.local` in the registry and server mDNS resolution is needed.
......@@ -31,7 +31,7 @@ Because we maybe want to build on the Raspberry Pis (`armv7` architecture) we ca
But we can use a [port for `armv7`](https://hub.docker.com/r/arm32v7/maven/).
If you want to build the container on your own `amd64` or `x86` machine you have to choose another image, eg. the [official Apache Maven image](https://hub.docker.com/_/maven).
You can do this by adding `--build-arg MVN_IMAGE=maven:3-jdk-11-slim` to the [`docker build` command](#building-the-container) or the `docker-compose` configuration.
You can do this by adding `--build-arg MVN_IMAGE=maven:3-jdk-11-slim` to the [`docker build` command](#building-the-container) or the `docker-compose.yml` configuration.
**Be sure to always use an image that uses Java 11!**
......@@ -40,7 +40,7 @@ ARG JRE_IMAGE=eclipse-temurin:11-jre
```
This does the same as above and the defined argument is used as image in the [runtime stage](#runtime-stage).
The image defined as default should work fine on `armv7`, `amd64` and `x86` systems, so you probably wont need to change it.
If you still want to use another image you can add `--build-arg MVN_IMAGE=your_image` to the [`docker build` command](#building-the-container) or the `docker-compose` configuration.
If you still want to use another image you can add `--build-arg MVN_IMAGE=your_image` to the [`docker build` command](#building-the-container) or the `docker-compose.yml` configuration.
**Be sure to always use an image that provides the JRE 11!**
The JDK is not necessary.
......@@ -141,7 +141,7 @@ It would probably be cleaner to use the `ENV` definition in the Dockerfile but s
## 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.
If you want to create a new file for `docker compose` you can use this sample as a reference.
## Building the Container
......@@ -156,11 +156,11 @@ If you change it, be sure to replace the tag name in any following command in th
To change the used images for the build and runtime stages, add `--build-args MVN_IMAGE=...` and/or `build-args JRE_IMG=...` to the build command.
It is also possible to use `docker-compose` to build the container.
It is also possible to use `docker compose` to build the container.
```console
# docker-compose [-f filename.yml] build
# docker compose [-f filename.yml] build
```
To change the used images for in the build with `docker-compose`, you have to add the arguments to the config.
To change the used images for in the build with `docker compose`, you have to add the arguments to the config.
See [here](https://docs.docker.com/compose/compose-file/compose-file-v3/#args) how to do this.
## Running the Container
......@@ -204,8 +204,8 @@ 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
`docker-compose` can be used to set up whole stacks of containers with one configuration file.
## 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).
......@@ -213,14 +213,14 @@ 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
# 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
# docker compose down
```
To start or stop only single services defined inside your config you can append the service names to the `up` or `down` commands.
......@@ -235,8 +235,8 @@ To start or stop only single services defined inside your config you can append
6. `sudo systemctl disable i4.0-demo.service`
7. Install docker if necessary: `curl -sSL https://get.docker.com | sh`
8. In case the following doesn't work, a reboot can help.
9. `sudo docker-compose build`
10. `sudo docker-compose up -d`
9. `sudo docker compose build`
10. `sudo docker compose up -d`
You can also use the default docker commands.
As long as the containers are started with `restart: always` or `restart: unless-stopped` they will start on boot.
\ No newline at end of file