下载confd

#wget https://github.com/kelseyhightower/confd/releases/download/v0.15.0/confd-0.15.0-linux-amd64 #mv confd-0.15.0-linux-amd64 /usr/bin/confd #chmod +x /usr/bin/confd ​

创建confd目录

conf.d 目录中是应用的配置文件定义
templates 目录中是应用的模版文件
confd.toml 是confd本身的配置文件
mkdir -p /etc/confd/{conf.d,templates}

root@747f14c47586:/etc/confd/conf.d# cat nginx.toml 
[template]
src = "nginx.conf.tmpl"
dest = "/etc/nginx/conf.d/default.conf"
keys = [ "/netm/url" ]
check_cmd = "/etc/init.d/nginx configtest"
reload_cmd = "/etc/init.d/nginx reload"

root@747f14c47586:/etc/confd/templates# cat nginx.conf.tmpl 
server {
		listen 80;
		location /netm/index.jsp {
				rewrite ^(.*)$ {{ getv "/netm/url" }} redirect;
				expires 1s;
		}
}

dockfile

FROM centos
MAINTAINER cxiong

# yum
#RUN yum -y update
#RUN yum -y install epel-release
#RUN yum clean all
#RUN yum makecache

#RUN yum -y install iproute

# confd
RUN yum -y install wget

RUN wget https://github.com/kelseyhightower/confd/releases/download/v0.15.0/confd-0.15.0-linux-amd64

RUN mv confd-0.15.0-linux-amd64 /usr/bin/confd
RUN chmod +x /usr/bin/confd
RUN mkdir -p /etc/confd/{conf.d,templates}
COPY nginx.toml /etc/confd/conf.d/
COPY nginx.conf.tmpl /etc/confd/templates/

# nginx 
RUN rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
RUN yum -y install nginx 
RUN sed -i '3a daemon off;' /etc/nginx/nginx.conf
EXPOSE 80

# etcd
#RUN wget https://github.com/coreos/etcd/releases/download/v3.3.9/etcd-v3.3.9-linux-amd64.tar.gz
#RUN tar xzvf etcd-v3.3.9-linux-amd64.tar.gz
#RUN mv etcd-v3.3.9-linux-amd64/etcd* /usr/bin/
#chmod +x /usr/bin/etcd*

RUN yum -y install epel-release
RUN yum -y install etcd
#EXPOSE 2379

# check_netm_url.sh
COPY check_netm_url.sh /
RUN chmod +x /check_netm_url.sh


# supervisor
#RUN yum -y install epel-release
RUN yum -y install supervisor


# cmd 
COPY nginx.ini /etc/supervisord.d/
COPY confd.ini /etc/supervisord.d/
COPY etcd.ini /etc/supervisord.d/
COPY check_netm_url.ini /etc/supervisord.d/

ENTRYPOINT /usr/bin/supervisord -n -c /etc/supervisord.conf
#CMD /usr/bin/supervisord