Let's explore what we just created:
$ docker network inspect authnet
This prints out a large JSON object describing the network, and its attached containers, which we've looked at before. If all went well, we'll see there are now two containers attached to authnet where there'd previously been only one.
Let's go into the userauth container and poke around:
$ docker exec -it userauth bash
root@a29d833287bf:/userauth# ls
node_modules user-server.mjs users-list.js
package-lock.json users-add.js users-sequelize.mjs
package.json users-delete.js
sequelize-docker-mysql.yaml users-find.js
The /userauth directory is inside the container and is exactly the files placed in the container using the COPY command, plus the installed files in node_modules:
root@a29d833287bf:/userauth# PORT=3333 node users-list.js
List []
root@a29d833287bf:/userauth# PORT=3333 node users-add.js
Created { id: 1, username: 'me', password: 'w0rd', provider: 'local',
familyName: 'Einarrsdottir', givenName: 'Ashildr',
middleName: '', emails: '[]', photos: '[]',
updatedAt: '2018-02-05T01:54:53.320Z', createdAt: '2018-02-
05T01:54:53.320Z' }
root@a29d833287bf:/userauth# PORT=3333 node users-list.js
List [ { id: 'me', username: 'me', provider: 'local',
familyName: 'Einarrsdottir', givenName: 'Ashildr', middleName: '',
emails: '[]', photos: '[]' } ]
Our test of adding a user to the authentication service works:
root@a29d833287bf:/userauth# ps -eafw
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 01:52 pts/0 00:00:00 /bin/sh -c npm run docker
root 9 1 0 01:52 pts/0 00:00:00 npm
root 19 9 0 01:52 pts/0 00:00:00 sh -c node --experimental-modules ./user-server
root 20 19 0 01:52 pts/0 00:00:01 node --experimental-modules ./user-server
root 30 0 0 01:54 pts/1 00:00:00 bash
root 70 30 0 01:57 pts/1 00:00:00 ps -eafw
root@a29d833287bf:/userauth# ping db-userauth
PING db-userauth (172.18.0.2): 56 data bytes
64 bytes from 172.18.0.2: icmp_seq=0 ttl=64 time=0.105 ms
64 bytes from 172.18.0.2: icmp_seq=1 ttl=64 time=0.077 ms
^C--- db-userauth ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.077/0.091/0.105/0.000 ms
root@a29d833287bf:/userauth# ping userauth
PING userauth (172.18.0.3): 56 data bytes
64 bytes from 172.18.0.3: icmp_seq=0 ttl=64 time=0.132 ms
64 bytes from 172.18.0.3: icmp_seq=1 ttl=64 time=0.095 ms
^C--- userauth ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
The process listing is interesting to study. Process PID 1 is the npm run docker command in the Dockerfile. Processes proceed from there to the node process running the actual server.
A ping command proves the two containers are available as hostnames matching the container names.
Then, you can log in to the db-userauth container and inspect the database:
$ docker exec -it db-userauth bash
bash-4.2# mysql -u userauth -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
...
mysql> use userauth
Database changed
mysql> show tables;
+--------------------+
| Tables_in_userauth |
+--------------------+
| Users |
+--------------------+
1 row in set (0.00 sec)
mysql> select * from Users;
+----+----------+----------+----------+---------------+-----------+--...
| id | username | password | provider | familyName | givenName | ...
+----+----------+----------+----------+---------------+-----------+--...
| 1 | me | w0rd | local | Einarrsdottir | Ashildr | ...
+----+----------+----------+----------+---------------+-----------+--...
1 row in set (0.00 sec)
We have successfully Dockerized the user authentication service in two containers, db-userauth and userauth. We've poked around the insides of a running container and found some interesting things. But, our users need the fantastic Notes application to be running, and we can't afford to rest on our laurels.