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.
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.