1. 程式人生 > >Dockerfile建立consul 叢集

Dockerfile建立consul 叢集

Dockerfile建立consul 叢集
cd /opt
mkdir consul
cd consul
mkdir data
mkdir consul.d
vi Dockerfile

FROM centos:latest
MAINTAINER YTO
COPY consul /usr/local/bin
EXPOSE 8300
EXPOSE 8301 8301/udp 8302 8302/udp
EXPOSE 8500 8600 8600/udp

dokcer build -t consul/dong .
dokcer build -t consul/ya .
dokcer build -t consul/di .
#用dockerfile建立3個映象
docker run -it -d -p 8500:8500 --name consuldong consul/dong /bin/bash
docker run -it -d -p 8503:8500 --name consulya consul/ya /bin/bash
docker run -it -d -p 8502:8500 --name consulya consul/di /bin/bash
#分別啟動映象

進入容器:docker exec -it imageID /bin/bash
cd /usr/local/bin
#master 啟動方式
nohup consul agent -server -bootstrap-expect=1 -data-dir=/opt/consul/data -node=internal IP -bind=internal IP -datacenter=dc1 -rejoin -config-dir /opt/consul/consul.d -client 0.0.0.0 -ui &
#slave啟動方式
nohup consul agent -server -data-dir=/opt/consul/data -node=internal IP -bind=internal IP -datacenter=dc1 -rejoin -client 0.0.0.0 &

在slave上執行consul join master IP