DBSync worker container

Now we can add the dbsync worker that applies migrations to a database instance. We use a local image that will be built with Dockerfile from the ./microservices/dbsync folder that we used as a value for the build parameter. This worker depends on a database container (called db) and we set this dependency with the depends_on parameter.

Dependencies don't mean the dependant container will be started when the necessary application is ready to work. It only refers to the order in which containers are started; the application that your microservice needs might not be ready. You have to control the readiness of the application, as we did for dbsync, with a loop that tries to connect to a database till it is available.

Also, we set the RUST_LOG variable with the filtering of messages with one level less than debug and printed messages related to the dbsync_worker module only:

dbsync:
build: ./microservices/dbsync
depends_on:
- db
environment:
- RUST_LOG=dbsync_worker=debug
- RUST_BACKTRACE=1
- DBSYNC_DATABASE=postgresql://postgres:password@db:5432

We also activated backtrace printing by setting the RUST_BACKTRACE variable.

The last variable sets a connection link to a database. As you can see, we use the db name of the host since Docker configures containers to resolve names and match the names of other containers, so you don't need to set or remember the IP address of the container. You can use the names of containers as host names.

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

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