Docker application on the Win10: Docker-compose (container arrangement)

Read catalog:

 

Preface:

  Docker yesterday completed the introductory example ( Docker application: the Hello World ), only a rough example shows probably stand-alone application deployment process in Docker in;

But even if not considered large-scale projects associated with multiple application services, but only stand-alone application deployment, the process is slightly more complex.

  Because now the software company to develop, test, deploy basically separate, and even referred to a different person to complete all phases of the software if you want to deploy a large number of knock write command,

It is very easy to make mistakes; even some companies just operation and maintenance personnel, engineering personnel deployment, once a problem, they want to find out why the basic hard.

So called for the deployment must be close to the fool, so with choreography container technology.

 

First, the remaining issues

  Examples of yesterday are left with a number of issues, such as the IP address changes after container restart, restart the application container after container-related remote services will fail, this is very deadly.

The second problem is a communication network, the example of the Web yesterday Mysql call by mapping ip, access to the outside of the container inside another container data, as follows:

1 conn = new MySqlConnection("server=198.198.198.181;User Id=root;password=mima2100;Database=mysql-db");

198.198.198.181 is my local machine LAN IP, because of this IP, Web applications have led to a hard couple of Mysql containers, need to find ways to get rid of.

 

Second, to solve the problem

1, in fact, simple, create a docker-compose.yml file in the same directory as the file Dockerfile

Copy the code
 1 version: '3'
 2 services:
 3   web:
 4       build: .
 5       ports:
 6        - "8000:80"
 7       depends_on:
 8        - mysql
 9   mysql:
10     container_name: mysql_dc
11     environment:
12       - MYSQL_ROOT_PASSWORD=mima2100
13     image: mysql
14     ports:
15       - "3306:3306"
Copy the code

2, the top of the docker-compose.yml file format, other parameters of the respective Baidu, meaning is to create two applications: web, mysql

2.1, web directly in this build (also downloaded from the mirror mode), the port 80 is mapped to a local port 8000, dependent mysql

2.2, mysql specify the login password mima2100, container port mapping to the local 3306 3306

2.3, Mysql connections read as follows:

Copy the code
 1 using Dapper;
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Data;
 5 using System.Threading.Tasks;
 6 using MySql.Data.MySqlClient;
 7 
 8 namespace WebApp_HelloWorld.Controllers
 9 {
10     public class DBService
11     {
12         protected IDbConnection conn;
13 
14         public DBService()
15         {
16             conn = new MySqlConnection("server=mysql_dc;User Id=root;password=mima2100;Database=mysql-db");
17         }
18 
19         public async Task<T> Single<T>(string sql, object paramPairs = null)
20         {
21             return await conn.QuerySingleOrDefaultAsync<T>(sql, paramPairs);
22         }
23 
24         public async Task<int> Count(string sql, object paramPairs = null)
25         {
26             return await conn.QuerySingleOrDefaultAsync<int>(sql, paramPairs);
27         }
28     }
29 }
Copy the code

 

Third, verify

1, verify docker-compose version

1 docker-compose version

2, the positioning to the web directory, input command

1 docker-compose up -d

 

3. Check the container

1 docker ps -a

Mysql can see the web have created successful, no error.

4, about the visit localhost: 8000

Get. .

 

 

Source: https://www.cnblogs.com/lanxiaoke/p/10439282.html

Read catalog:

 

Preface:

  Docker yesterday completed the introductory example ( Docker application: the Hello World ), only a rough example shows probably stand-alone application deployment process in Docker in;

But even if not considered large-scale projects associated with multiple application services, but only stand-alone application deployment, the process is slightly more complex.

  Because now the software company to develop, test, deploy basically separate, and even referred to a different person to complete all phases of the software if you want to deploy a large number of knock write command,

It is very easy to make mistakes; even some companies just operation and maintenance personnel, engineering personnel deployment, once a problem, they want to find out why the basic hard.

So called for the deployment must be close to the fool, so with choreography container technology.

 

First, the remaining issues

  Examples of yesterday are left with a number of issues, such as the IP address changes after container restart, restart the application container after container-related remote services will fail, this is very deadly.

The second problem is a communication network, the example of the Web yesterday Mysql call by mapping ip, access to the outside of the container inside another container data, as follows:

1 conn = new MySqlConnection("server=198.198.198.181;User Id=root;password=mima2100;Database=mysql-db");

198.198.198.181 is my local machine LAN IP, because of this IP, Web applications have led to a hard couple of Mysql containers, need to find ways to get rid of.

 

Second, to solve the problem

1, in fact, simple, create a docker-compose.yml file in the same directory as the file Dockerfile

Copy the code
 1 version: '3'
 2 services:
 3   web:
 4       build: .
 5       ports:
 6        - "8000:80"
 7       depends_on:
 8        - mysql
 9   mysql:
10     container_name: mysql_dc
11     environment:
12       - MYSQL_ROOT_PASSWORD=mima2100
13     image: mysql
14     ports:
15       - "3306:3306"
Copy the code

2, the top of the docker-compose.yml file format, other parameters of the respective Baidu, meaning is to create two applications: web, mysql

2.1, web directly in this build (also downloaded from the mirror mode), the port 80 is mapped to a local port 8000, dependent mysql

2.2, mysql specify the login password mima2100, container port mapping to the local 3306 3306

2.3, Mysql connections read as follows:

Copy the code
 1 using Dapper;
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Data;
 5 using System.Threading.Tasks;
 6 using MySql.Data.MySqlClient;
 7 
 8 namespace WebApp_HelloWorld.Controllers
 9 {
10     public class DBService
11     {
12         protected IDbConnection conn;
13 
14         public DBService()
15         {
16             conn = new MySqlConnection("server=mysql_dc;User Id=root;password=mima2100;Database=mysql-db");
17         }
18 
19         public async Task<T> Single<T>(string sql, object paramPairs = null)
20         {
21             return await conn.QuerySingleOrDefaultAsync<T>(sql, paramPairs);
22         }
23 
24         public async Task<int> Count(string sql, object paramPairs = null)
25         {
26             return await conn.QuerySingleOrDefaultAsync<int>(sql, paramPairs);
27         }
28     }
29 }
Copy the code

 

Third, verify

1, verify docker-compose version

1 docker-compose version

2, the positioning to the web directory, input command

1 docker-compose up -d

 

3. Check the container

1 docker ps -a

Mysql can see the web have created successful, no error.

4, about the visit localhost: 8000

Get. .

 

Guess you like

Origin www.cnblogs.com/mq0036/p/11722402.html