一个部署包含nginx tomcat mysql等,这种有多种部署,容器编排。

Docker compose
单机多容器部署
通过yml定义多容器部署
win/mac默认提供docker compose,linux需要安装

案例 官网 https://docs.docker.com/compose/install/
get started with wordpress
安装compose

  1. 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
  2. #授权
  3. sudo chmod +x /usr/local/bin/docker-compose
  4. #测试
  5. docker-compose --version

WordPress创建

  1. 创建空目录

mkdir my_wordpress
cd my_wordpress

  1. 创建.yml ``` version: ‘3.3’

services: db: image: mysql:5.7 volumes:

  1. - db_data:/var/lib/mysql
  2. restart: always
  3. environment:
  4. MYSQL_ROOT_PASSWORD: somewordpress
  5. MYSQL_DATABASE: wordpress
  6. MYSQL_USER: wordpress
  7. MYSQL_PASSWORD: wordpress

wordpress: depends_on:

  1. - db
  2. image: wordpress:latest
  3. ports:
  4. - "8000:80"
  5. restart: always
  6. environment:
  7. WORDPRESS_DB_HOST: db:3306
  8. WORDPRESS_DB_USER: wordpress
  9. WORDPRESS_DB_PASSWORD: wordpress
  10. WORDPRESS_DB_NAME: wordpress

volumes: db_data: {} ``` 先构建mysql 然后拉去wordpress容器

  1. 构建 docker-compose up -d

实战
docker run —name 容器名 -e MYSQL_ROOT_PASSWORD=password -d mysql:tag
-e: 指定环境变量

MYSQL_ROOT_PASSWORD官方变量设置,还有很多,这个是设置密码
在/docker-entrypoint-init.db.d 下放入初始化脚本就完成脚本的初始化