Docker Compose

docker compose可以实现同时build多个镜像,并且同时启动多个容器;

https://docker_practice.gitee.io/compose/compose_file.html

docker compose使用yaml语法来定义配置文件,可以查看阮大师关于yaml的说明:

http://www.ruanyifeng.com/blog/2016/07/yaml.html

 

(1)首先使用visual studio 脚手架来帮我们创建一个带dockerfile的.net core web api项目,

然后定义以下yaml的配置文件:

 

 

version:'20191021'

services:
  db:
     image:mysql/mysql-server #docker repository name
     command:mysql --character-set-server=utf8 --collation-server=utf8_general_ci #character encoding
     restart:always
     ports:
       - '3306:3306' #port mapping
     environment:
       - MYSQL_ROOT_PASSWORD=pwd12345
       - MYSQL_USER=daniel
       - MYSQL_PASSWORD=pwd12345
     volumes:
       - /d/docker/database/mysql-init:/docer-entrypoint-initdb.database #authorization for docker database

  web:
    build: . #build at current directory
    container_name: 'aspnetcoretest'
    ports:
     - '8003:80'
    depends_on:
     - db  #create depend relationship

(2)运行docker build 然后查看镜像生成情况.

(3)docker-compose up启动容器.

转载于:https://www.cnblogs.com/cby-love/p/11149117.html

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐