Composing all services

The configuration file can now be completed so that Docker Compose not only starts Traefik, but also Minio and the encoding server. Let's start with the Minio service, by adding this block to the configuration file:

  minio:
image: minio/minio
command: server /data
ports:
- "9000:9000"
volumes:
- ./data:/data
- ./config:/root/.minio
environment:
MINIO_ACCESS_KEY: IU0645L6OOSV96GSEG72
MINIO_SECRET_KEY: udTdXiaUh1equB7BE9Kn691a/DNGnMguIVEh0iyu

Two environment variables are provided here. They allow us to fix the credentials being used by this instance, instead of letting Minio generate them during the first start.

This container can be started with the following command:

$ docker-compose up -d minio

Then, a third service can be added for the audio encoder:

  audio-encoder:
image: audio-encoder
depends_on:
- reverse-proxy
- minio
expose:
- 3000
volumes:
- ./config.json:/opt/audio-encoder/config.json
labels:
- "traefik.frontend.rule=PathPrefix:/api/transcode/v1"
- "traefik.port=3000"

There are two new sections being used here. The depends-on section indicates that this container depends on the reverse-proxy and minio containers. When the audio-encoder container is started, Docker Compose first ensures that these two containers are started. If either of them has not started yet, then they are started automatically.

Next, two labels are provided:

  • frontend.rule specifies the frontend rules to associate to this backend. Here, all requests with a path starting with /api/transcode/v1 are routed to the audio-encoder backend.
  • The port label indicates to Traefik which port should be used to route the traffic. This label is optional in this case because the container exposes only one port, so Traefik can determine this value automatically.

The audio-encoder container is started by using the following code:

$ docker-compose up -d audio-encoder

Now, the web interface of Traefik should display a frontend for audio encoding APIs and a backend composed of one server. The following screenshot shows the frontend part:

Figure 11.9: The audio encode server route via Traefik

Instead of starting each backend one by one, it is possible to start them all at once with the following command:

$ docker-compose up -d

The d option is similar to the option for the Docker run command: it tells Docker to detach from the container once it is started.

The whole stack can also be stopped with a single command:

$ docker-compose down

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.247.11