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启动容器.
所有评论(0)