欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Docker Compose

程序员文章站 2022-05-15 09:17:09
...

概述

Docker Compose单机多容器部署工具

通过yml定义多容器如何部署

相关文件

[[email protected] 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为网络请求库

[[email protected] ~]# sudo chmod +x /usr/local/bin/docker-compose

[[email protected] ~]# docker-compose --version

docker-compose version 1.25.0, build 0a186604

此时,安装成功

概述
Docker Compose单机多容器部署工具
通过yml定义多容器如何部署
相关文件
[[email protected] 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为网络请求库 
[[email protected] ~]# sudo chmod +x /usr/local/bin/docker-compose
[[email protected] ~]# 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/ 
 
移除
[[email protected] wordpress]# docker-compose down –volumes

启动

cd wordpress/

docker-compose up –d

访问

http://192.168.32.17:8000/

 

移除

[[email protected] wordpress]# docker-compose down –volumes