官术网_书友最值得收藏!

Creating deployment files and testing locally

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:

version: '3.3'

services:

signup-db:
image: db-image:v1
networks:
- app-net

signup-app:
image: app-image:v1
ports:
- "8000:80"
depends_on:
- signup-db
networks:
- app-net

networks:
app-net:
external:
name: nat

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. 

主站蜘蛛池模板: 盐边县| 康定县| 佳木斯市| 克拉玛依市| 璧山县| 东乡族自治县| 汶上县| 四川省| 武定县| 渝中区| 丹寨县| 甘肃省| 聂荣县| 临湘市| 枣庄市| 广德县| 湘阴县| 枣庄市| 神池县| 竹北市| 都匀市| 巴东县| 安泽县| 临夏市| 宜兰县| 治多县| 东安县| 望都县| 望城县| 汕尾市| 南投市| 尤溪县| 林周县| 静乐县| 郸城县| 甘洛县| 苏尼特右旗| 河南省| 遵义县| 榆社县| 锦州市|