docker-compose(单机版的容器编排工具)

ansible剧本

yum install -y python2-pip(需要epel源)
pip install docker-compose(默认pypi源在国外)  这条命令不执行,执行下面的命令,加过速的
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple docker-compose 临时加速

  

##pip 加速
##详细指令
http://www.jianshu.com/p/2217cfed29d7
在这里创建一个目录,写好docker-compose配置文件,注意一定是docker-compose.yml文件名

cd 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
     volumes:
       - web_data:/var/www/html
     ports:
       - "80:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
volumes:
    db_data:
    web_data:
#启动
docker-compose up
.....................................
ys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1         | 2019-07-06T13:00:43.376082Z 0 [Note] Event Scheduler: Loaded 0 events
db_1         | 2019-07-06T13:00:43.376296Z 0 [Note] mysqld: ready for connections.
db_1         | Version: '5.7.15'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
wordpress_1  | WordPress not found in /var/www/html - copying now...
wordpress_1  | Complete! WordPress has been successfully copied to /var/www/html
wordpress_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message
wordpress_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message
wordpress_1  | [Sat Jul 06 13:00:46.643865 2019] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/7.3.6 configured -- resuming normal operations
wordpress_1  | [Sat Jul 06 13:00:46.643951 2019] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'    在这里就夯住了,这是正确的,容易需要夯住才能运行


这里和docker logs 容器ID 去查看日志是一样的

  

这里使用的是debian的系统,用的是apache作为web,可以页面测试:
Docker-compose介绍

 

Docker-compose介绍

 

#后台启动

[root@docker1 web]# docker-compose up -d
Starting web_db_1 ... done
Starting web_wordpress_1 ... done

关闭的命令是down

[root@docker1 web]# docker-compose down
Stopping web_wordpress_1 ... done
Stopping web_db_1        ... done
Removing web_wordpress_1 ... done
Removing web_db_1        ... done
Removing network web_defaul

 更多内容关注https://docs.docker.com官网介绍...................