概述
Docker Compose单机多容器部署工具
通过yml定义多容器如何部署
相关文件
[root@rabbitmq1 wordpress]# ls
docker-compose.yml
安装
地址
https://docs.docker.com/compose/install/
命令
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
如果出现问题:
fatal: unable to access 'https://github.com/wenshaoyan/function-interceptor/': Peer reports incompatible or unsupported protocol version.
解决方法:
sudo yum update nss curl # nss为名称解析和认证服务 curl为网络请求库
[root@rabbitmq1 ~]# sudo chmod +x /usr/local/bin/docker-compose
[root@rabbitmq1 ~]# docker-compose --version
docker-compose version 1.25.0, build 0a186604
此时,安装成功
概述
Docker Compose单机多容器部署工具
通过yml定义多容器如何部署
相关文件
[root@rabbitmq1 wordpress]# ls
docker-compose.yml
安装
地址
https://docs.docker.com/compose/install/
命令
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
如果出现问题:
fatal: unable to access 'https://github.com/wenshaoyan/function-interceptor/': Peer reports incompatible or unsupported protocol version.
解决方法:
sudo yum update nss curl # nss为名称解析和认证服务 curl为网络请求库
[root@rabbitmq1 ~]# sudo chmod +x /usr/local/bin/docker-compose
[root@rabbitmq1 ~]# docker-compose --version
docker-compose version 1.25.0, build 0a186604
此时,安装成功
version: '3.3'
services: //服务安装镜像的前后顺序
db: //自己定义
image: mysql:5.7 #docker run mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always # 自动重启
environment: #运行效果为docker run -e MYSQL_ROOT_PASSWORD = somewordpress
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress: //自己定义
depends_on: #运行效果为docker --link db
- 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: {}
注释:
db_data与volumes:db_data: {}对应
此时,是空值,运行效果是 -v empty:/var/lib/mysql
如果有值,对应是物理机的路径,路径下可以放sql,构建时就会将sql加载的db中
启动
cd wordpress/
docker-compose up –d
访问
http://192.168.32.17:8000/
移除
[root@rabbitmq1 wordpress]# docker-compose down –volumes
启动
cd wordpress/
docker-compose up –d
访问
移除
[root@rabbitmq1 wordpress]# docker-compose down –volumes