Docker进阶-Docker Compose
官方文档:https://docs.docker.com/compose/
简介
Docker
DockerFile -> bulid(形成镜像)-> run
Docker Compose 就可以轻松搞笑的来管理这些容器。以及定义和运行容器
官方介绍
定义运行多个容器
YAML file 配置文件
single command 简单命令 有哪些?
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. To learn more about all the features of Compose, see the list of features.
所有环境都可以使用 Docker Compose production、development、staging、testing
Compose works in all environments: production, staging, development, testing, as well as CI workflows. You can learn more about each case in Common Use Cases.
三步骤
Using Compose is basically a three-step process:
1.Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
。Dockerfile保证我们的项目在任何地方可以运行
2.Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
。services 什么是服务?
。docker-compose.yml 这个文件如何写?
3.Run docker compose up and the Docker compose command starts and runs your entire app. You can alternatively run docker-compose up using the docker-compose binary.
。启动项目
作用:批量容器编排。
个人理解
Compose 是Docker官方开源的项目,需要进行安装。
Dockerfile 让程序在任何地方运行。 web redis mysql nginx 。。。。 多个容器。
Compose
version: "3.9" # optional since v1.27.0
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
- log