We're using a different file for SEQUELIZE_CONNECT. Create a new file named users/sequelize-docker-mysql.yaml containing the following:
dbname: userauth
username: userauth
password: userauth
params:
host: db-userauth
port: 3306
dialect: mysql
The difference is that instead of localhost as the database host, we use db-userauth. Earlier, we explored the db-userauth container and determined that was the hostname of the container. By using db-userauth in this file, the authentication service will use the database in the container.
Now we need to take care of the environment variable named REST_LISTEN. Previously, the authentication server had listened only to http://localhost:3333. We'd done this for security purposes, that is, to limit which processes could connect to the service. Under Docker, we need to connect to this service from outside its container so that other containers can connect to this service. Therefore, it must listen to connections from outside the localhost.
In users-server.mjs, we need to make the following change:
server.listen(process.env.PORT,
process.env.REST_LISTEN ? process.env.REST_LISTEN : "localhost",
() => { log(server.name +' listening at '+ server.url); });
That is, if the REST_LISTEN variable exists, the REST server is told to listen to whatever it says, otherwise the service is to listen to localhost. With the environment variable in the Dockerfile, the authentication service will listen to the world (0.0.0.0). Are we throwing caution to the wind and abrogating our fiduciary duty in keeping the sacred trust of storing all this user identification information? No. Be patient. We'll describe momentarily how to connect this service and its database to AuthNet and will prevent access to AuthNet by any other process.