一个部署包含nginx tomcat mysql等,这种有多种部署,容器编排。
Docker compose
单机多容器部署
通过yml定义多容器部署
win/mac默认提供docker compose,linux需要安装
案例 官网 https://docs.docker.com/compose/install/
get started with wordpress
安装compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.28.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
#授权
sudo chmod +x /usr/local/bin/docker-compose
#测试
docker-compose --version
WordPress创建
- 创建空目录
mkdir my_wordpress
cd my_wordpress
- 创建.yml ``` version: ‘3.3’
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
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: {} ``` 先构建mysql 然后拉去wordpress容器
- 构建 docker-compose up -d
实战
docker run —name 容器名 -e MYSQL_ROOT_PASSWORD=password -d mysql:tag
-e: 指定环境变量
MYSQL_ROOT_PASSWORD官方变量设置,还有很多,这个是设置密码
在/docker-entrypoint-init.db.d 下放入初始化脚本就完成脚本的初始化