On Windows, we're able to run the commands in this section unchanged.
Before deploying this to a server, let's run it on our laptop using docker-compose:
$ docker stop db-notes userauth db-auth notesapp db-notes userauth db-auth notesapp $ docker rm db-notes userauth db-auth notesapp db-notes userauth db-auth notesapp
We first needed to stop and delete the existing containers. Because the compose file wants to launch containers with the same names as we'd built earlier, we also have to remove the existing containers:
$ docker-compose build Building db-auth .. lots of output $ docker-compose up Creating db-auth Recreating compose_db-notes_1 Recreating compose_userauth_1 Recreating compose_notesapp_1 Attaching to db-auth, db-notes, userauth, notesapp
Once that's done, we can build the containers, docker-compose build, and then start them running, docker-compose up.
The first test is to execute a shell in userauth to run our user database script:
$ docker exec -it userauth bash
root@9972adbbdbb3:/userauth# PORT=3333 node users-add.js
Created { id: 2,
username: 'me', password: 'w0rd', provider: 'local',
familyName: 'Einarrsdottir', givenName: 'Ashildr', middleName: '',
emails: '[]', photos: '[]',
updatedAt: '2018-02-07T02:24:04.257Z', createdAt: '2018-02-07T02:24:04.257Z' }
root@9972adbbdbb3:/userauth#
Now that we've proved that the authentication service will work, and, by the way, created a user account, you should be able to browse to the Notes application and run it through its paces.
You can also try pinging different containers to ensure that the application network topology has been created correctly.
By default, docker-compose attaches to the containers so that logging output is printed on the Terminal. Output from all four containers will be intermingled together. Thankfully, each line is prepended by the container name.
When you're done testing the system, simply type CTRL + C on the Terminal:
^CGracefully stopping... (press Ctrl+C again to force)
Stopping db-userauth ... done
Stopping userauth ... done
Stopping db-notes ... done
Stopping notes ... done
To avoid running with the containers attached to the Terminal, use the -d option. This says to detach from the Terminal and run in the background.
An alternate way to bring down the system described in the compose file is with the docker-compose down command.
The up command builds, recreates, and starts the containers. The build step can be handled separately using the docker-compose build command. Likewise, starting and stopping the containers can be handled separately by using the docker-compose start and docker-compose-stop commands.
In all cases, your command shell should be in the directory containing the docker-compose.yml file. That's the default name for this file. This can be overridden with the -f option to specify a different filename.