docker-compose(单机版的容器编排工具)
前面我们使用 Docker 的时候,定义 Dockerfile 文件,然后使用 docker build、docker run 等命令操作容器。
然而微服务架构的应用系统一般包含若干个微服务,每个微服务一般都会部署多个实例,如果每个微服务都要手动启停,
那么效率之低,维护量之大可想而知
使用 Docker Compose 可以轻松、高效的管理容器,它是一个用于定义和运行多容器 Docker 的应用程序工具
#详细用法和解释
http://www.jianshu.com/p/2217cfed29d7
#安装(需要先安装epel源)
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[[email protected] ~]# yum install -y python2-pip
##pip 加速(https://mirrors.tuna.tsinghua.edu.cn/help/pypi/)
[[email protected] ~]#pip install -i https://pypi.tuna.tsinghua.edu.cn/simple docker-compose
验证是否安装成功:
[[email protected] ~]# docker-compose -v
docker-compose version 1.24.1, build 4667896
[[email protected] ~]# docker-compose version
docker-compose version 1.24.1, build 4667896
docker-py version: 3.7.3
CPython version: 2.7.5
OpenSSL version: OpenSSL 1.0.2k-fips 26 Jan 2017
[[email protected] ~]#
#使用compose 起镜像,解决依懒关系,不然手动的,我们需要先起mysql数据库,然后在起wordpress容器。
#现在使用compose,只需要配置一下文件,一键启动
[[email protected] my_wordpress]# cd my_wordpress/
[[email protected] my_wordpress]# vi docker-compose.yml
version: ‘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:
- "80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:
#启动
[[email protected] my_wordpress]# docker-compose up
#后台启动 docker-compose up -d
Creating network "my_wordpress_default" with the default driver
Creating volume "my_wordpress_db_data" with default driver
Pulling wordpress (wordpress:latest)...
latest: Pulling from library/wordpress
8d691f585fa8: Already exists
cba12d3fd8b1: Pull complete
cda54d6474c8: Pull complete
412447ed0729: Pull complete
84de6fc539c3: Pull complete
#镜像已经起来了。wordpress:latest 和 mysql:5.7
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fe4bd03b54f0 wordpress:latest "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:32768->80/tcp my_wordpress_wordpress_1
96866c91ece8 mysql:5.7 "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp, 33060/tcp my_wordpress_db_1
d3f63deec7e0 progrium/consul "/bin/start -server …" 16 hours ago Up 28 minutes 53/tcp, 53/udp, 8300-8302/tcp, 8400/tcp, 8301-8302/udp, 0.0.0.0:8500->8500/tcp consul
1ec8ce3a4ac4 registry "/entrypoint.sh /etc…" 4 days ago Up 28 minutes 0.0.0.0:5000->5000/tcp goofy_burnell
[[email protected] ~]#
#这个时候网页访问32768端口(映射到容器80端口了)就可以安装wordpress 了
http://192.168.6.129:32768
原文地址:https://www.cnblogs.com/jim-xu/p/11824935.html