We now have the individual containers tested and it is time to create a docker-compose file that we can use to bring the application stack of services up and down together. Docker's compose tool (docker-compose) is part of free Docker. Historically, it has been a tool for defining and running multi-container applications on a single Docker node. However, in Docker 1.13, Docker introduced Swarm mode with extended functionality to run multi-container applications across multiple nodes. Docker uses the same YAML file format (although Docker Swarm extensions require version 3+) to configure your application's multiple services. When the docker-compose file is set up, we can start our database and application services/containers with one command.
Next, we have our docker-compose for local nodes. Following in our docker-compose.yml file, the image names are only local (no namespace in front of the image name) and need to be in the Docker host's image cache in order to be run. We will address this local image issue later. Also, notice the service names (bold in the following code), which will be used for DNS resolution when signup-app looks for signup-db in the connections string:
To run our application on a single node, we use the docker-compose up command. It is usually best to run the docker-compose commands in the same directory as docker-compose.yml. Next, we see the command being run and the subsequent log entries:
PS mta-netfx-dev-part-2\app> docker-compose up ... Creating app_signup-db_1_3084b8816d59 ... done Creating app_signup-app_1_cf2adb1663f8 ... done Attaching to app_signup-db_1_7dc594a2a1cf, app_signup-app_1_3c8d26d0a674 signup-db_1_7dc594a2a1cf | VERBOSE: Starting SQL Server signup-db_1_7dc594a2a1cf | VERBOSE: Changing SA login credentials signup-app_1_3c8d26d0a674 | Configuring DB connection signup-app_1_3c8d26d0a674 | Starting IIS signup-app_1_3c8d26d0a674 | Tailing log signup-db_1_7dc594a2a1cf | VERBOSE: No existing data files - will create new database signup-db_1_7dc594a2a1cf | VERBOSE: Changed database context to 'master'. signup-db_1_7dc594a2a1cf | VERBOSE: Changed database context to 'SignUpDb'. signup-db_1_7dc594a2a1cf | signup-app_1_3c8d26d0a674 | 2018-11-11 01:47:55,705 [1 ] INFO - Completed pre-load data cache, took: 7020ms signup-app_1_3c8d26d0a674 | 2018-11-11 01:48:14,908 [1 ] INFO - Starting pre-load data cache signup-app_1_3c8d26d0a674 | 2018-11-11 01:48:15,033 [1 ] INFO - Completed pre-load data cache, took: 99ms
(press Ctrl+C twice to terminate) $ docker-compose down ... clean up messages
Now, we have a docker-compose or stack file that we can use to run our application. However, if we want to be able to run that stack file from anywhere, we are going to need to rename and move the images to a central registry.