systemctl stop firewalld.service #中止firewall
systemctl disable firewalld.service #禁止firewall開機啓動 linux
yum install iptables-services #安裝
systemctl restart iptables.service #最後重啓防火牆使配置生效
systemctl enable iptables.service #設置防火牆開機啓動 nginx
yum install docker-io git
最新版本(2016-04-19)
curl -L https://github.com/docker/compose/releases/download/1.7.0/docker-compose-`uname -s-uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose github
#簡單的web服務器,能夠用 docker-compose scale web=n命令擴展到n個實例 web: image: yeasy/simple-web:latest environment: SERVICE_80_NAME: http SERVICE_NAME: web SERVICE_TAGS: backend ports: - "80" #ngnix負載均衡,使用consul-template自動加載配置 lb: image: yeasy/nginx-consul-template:latest hostname: lb links: - consulserver:consul ports: - "80:80" #consul服務端,能夠方便管理docker container consulserver: image: gliderlabs/consul-server:latest hostname: consulserver ports: - "8300" - "8400" - "8500:8500" - "53" command: -data-dir /tmp/consul -bootstrap -client 0.0.0.0 #監聽本地的docker sock,並將web服務器的container註冊到consul服務端 #listen on local docker sock to register the container with public ports to the consul service registrator: image: gliderlabs/registrator:master hostname: registrator links: - consulserver:consul volumes: - "/var/run/docker.sock:/tmp/docker.sock" command: -internal consul://consul:8500
docker-compose up #在docker-compose.yml所在的目錄下
日誌實例: web
#consulserver_1是consul的服務端日誌 #lb_1是ngnix的日誌 [root@localhost docker-compose]# docker-compose up Recreating dockercompose_web_1... Recreating dockercompose_consulserver_1... Recreating dockercompose_lb_1... Recreating dockercompose_registrator_1... Attaching to dockercompose_web_1, dockercompose_consulserver_1, dockercompose_lb_1 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 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" 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" "-"
docker-compose scale web=3#擴展到3個實例 docker
[root@localhost docker-compose]# docker-compose scale web=3 Creating dockercompose_web_2... Creating dockercompose_web_3... Starting dockercompose_web_2... Starting dockercompose_web_3...
[root@localhost ~]# docker inspect --format "{{.State.Pid}}" dockercompose_web_1 3488 [root@localhost ~]# nsenter --target 3488 --mount --ipc --uts --net --pid root@0b1e4a76e802:/# ps PID TTY TIME CMD 59 ? 00: 00:00 bash 63 ? 00: 00:00 ps root@0b1e4a76e802:/#