51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1972|回复: 0
打印 上一主题 下一主题

CenOS 7.1安装Docker、Docker-compose

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2019-3-6 15:37:43 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
本帖最后由 天天酷派哦 于 2019-3-6 15:39 编辑

关闭centos7自带的firewall防火墙关闭firewall

systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动


安装iptables防火墙

yum install iptables-services #安装
systemctl restart iptables.service #最后重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动


安装docker

yum install docker-io


docker-compose template文件:docker-compose.yml
  1. #简单的web服务器,可以用 docker-compose scale web=n命令扩展到n个实例
  2. web:
  3.   image: yeasy/simple-web:latest
  4.   environment:
  5.     SERVICE_80_NAME: http
  6.     SERVICE_NAME: web
  7.     SERVICE_TAGS: backend
  8.   ports:
  9.   - "80"
  10. #ngnix负载均衡,使用consul-template自动加载配置
  11. lb:
  12.   image: yeasy/nginx-consul-template:latest
  13.   hostname: lb
  14.   links:
  15.   - consulserver:consul
  16.   ports:
  17.   - "80:80"
  18. #consul服务端,可以方便管理docker container
  19. consulserver:
  20.   image: gliderlabs/consul-server:latest
  21.   hostname: consulserver
  22.   ports:
  23.   - "8300"
  24.   - "8400"
  25.   - "8500:8500"
  26.   - "53"
  27.   command: -data-dir /tmp/consul -bootstrap -client 0.0.0.0
  28. #监听本地的docker sock,并将web服务器的container注册到consul服务端
  29. #listen on local docker sock to register the container with public ports to the consul service
  30. registrator:
  31.   image: gliderlabs/registrator:master
  32.   hostname: registrator
  33.   links:
  34.   - consulserver:consul
  35.   volumes:
  36.   - "/var/run/docker.sock:/tmp/docker.sock"
  37.   command: -internal consul://consul:8500
复制代码

使用docker-compose启动

docker-compose up #在docker-compose.yml所在的目录下
日志实例:

  1. #consulserver_1是consul的服务端日志
  2. #lb_1是ngnix的日志
  3. [root@localhost docker-compose]# docker-compose up
  4. Recreating dockercompose_web_1...
  5. Recreating dockercompose_consulserver_1...
  6. Recreating dockercompose_lb_1...
  7. Recreating dockercompose_registrator_1...
  8. Attaching to dockercompose_web_1, dockercompose_consulserver_1, dockercompose_lb_1
  9. consulserver_1 | ==> Failed to check for updates: Get https://checkpoint-api.hashicorp.com/v1/check/consul?arch=amd64&os=linux&signature=990d4634-bb34-ccad-b5fb-b1a4bfd1f4e9&version=0.6.3: dial tcp: lookup checkpoint-api.hashicorp.com on 202.96.128.86:53: read udp 172.17.0.2:36822->202.96.128.86:53: i/o timeout
  10. lb_1           | 2016/04/19 05:20:56 [error] 18#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.17.116, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:65535/", host: "192.168.17.160"
  11. lb_1           | 192.168.17.116 - - [19/Apr/2016:05:20:56 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36" "-"
复制代码

web容器扩容

docker-compose scale web=3#扩展到3个实例

  1. [root@localhost docker-compose]# docker-compose scale web=3
  2. Creating dockercompose_web_2...
  3. Creating dockercompose_web_3...
  4. Starting dockercompose_web_2...
  5. Starting dockercompose_web_3...
复制代码

连接docker container(借助nsenter)

  1. [root@localhost ~]# docker inspect --format "{{.State.Pid}}" dockercompose_web_1
  2. 3488
  3. [root@localhost ~]# nsenter --target 3488 --mount --ipc --uts --net --pid
  4. root@0b1e4a76e802:/# ps      
  5.   PID TTY          TIME CMD
  6.    59 ?        00: 00:00 bash
  7.    63 ?        00: 00:00 ps
  8. root@0b1e4a76e802:/#
复制代码



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-23 03:02 , Processed in 0.067650 second(s), 25 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表