DockerCompose
官网介绍:定义、运行多个容器。YAML file 配置文件。所有环境都能够应用。
应用步骤
1. 编写 Dockerfile
2. 编写 docker-compose.yml
3. 运行 docker-compose up
装置 compose
官网地址:https://docs.docker.com/compo…
sudo curl -L "https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose version
疾速开始
官网文档:https://docs.docker.com/compo…
mkdir composetest
cd composetest
vim app.py
vim requirements.txt
vim Dockerfile
vim docker-compose.yml
docker-compose up
测试
curl localhost:5000
进行
docker-compose down
扩大
docker images
CTRL + C
默认服务名:文件名_服务名_num
docker network ls
我的项目中的内容都在同个网络下,通过域名拜访 (如 localhost=redis)
YAML 配置编写规定
官网文档:https://docs.docker.com/compo…
#1. 版本
version: ''
#2. 服务
services:
服务 1: web
#服务配置(build,ports,volumes...)服务 2: redis,db...
#3. 其余配置(网络,卷挂载,全局配置...)volumes:
network:
config:
Compose 一键部署 WordPress
官网文档:https://docs.docker.com/sampl…
vim docker-compose.yml
version: "3.9"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- wordpress_data:/var/www/html
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
wordpress_data: {}
docker-compose up -d
-d 后盾启动