通过dockerfile构建haproxy镜像
结构
[root@docker ~]
/haproxy/
├── dockerfile
└── file
├── haproxy-2.4.0.tar.gz
└── harpoxy.cfg
haproxy.cfg
global
log 127.0.0.1 local0 info
maxconn 20480
pidfile /var/run/haproxy.pid
user haproxy
group haproxy
daemon
defaults
mode http
log global
option dontlognull
option httpclose
option httplog
option redispatch
balance roundrobin
timeout connect 10s
timeout client 10s
timeout server 10s
timeout check 10s
maxconn 60000
retries 3
listen admin_stats
bind 0.0.0.0:8189
stats enable
mode http
log global
stats uri /haproxy_stats
stats realm Haproxy\ Statistics
stats auth admin:admin
stats admin if TRUE
stats refresh 30s
listen webcluster
bind 0.0.0.0:80
mode http
log global
maxconn 3000
balance roundrobin
server web01 192.168.66.2:80 check inter 2000 fall 5
server web02 192.168.66.3:80 check inter 2000 fall 5
//创建dockerfile存放目录
[root@docker ~]
[root@docker ~]
[root@docker haproxy]
//编写dockerfile
[root@docker haproxy]
FROM centos
LABEL MAINTAINER='487021296@qq.com'
ENV verison 2.4.0
ADD file/haproxy-${verison}.tar.gz /usr/src
COPY file/haproxy.cfg /etc/haproxy/haproxy.cfg
RUN rm -rf /etc/yum.repos.d/* && \
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-$(awk -F'"' 'NR==5{print $2}' /etc/os-release).repo && \
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo && \
yum -y install make gcc pcre-devel bzip2-devel openssl-devel systemd-devel && \
useradd -r -M -s /sbin/nologin haproxy && \
cd /usr/src/haproxy-2.4.0/ && \
make -j $(nproc) TARGET=linux-glibc USE_OPENSSL=1 USE_PCRE=1 USE_SYSTEMD=1 && make install PREFIX=/usr/local/haproxy && \
cp /usr/local/haproxy/sbin/haproxy /usr/sbin && \
echo 'net.ipv4.ip_nonlocal_bind = 1' >> /etc/sysctl.conf && \
echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf && \
yum -y remove make gcc && \
rm -rf /var/cache/* && \
rm -rf /usr/src/haproxy-${version}
EXPOSE 80 8189
WORKDIR /usr/local/haproxy
ENTRYPOINT ["/usr/local/haproxy/sbin/haproxy"]
CMD ["-db","-f","/etc/haproxy/haproxy.cfg","-p","/var/run/haproxy.pid"]
//创建镜像
[root@docker haproxy]
[root@docker haproxy]
REPOSITORY TAG IMAGE ID CREATED SIZE
haproxy v0.1 44ff2a438db0 3 minutes ago 461MB
//创建haproxy容器
[root@docker ~]
40c18d1c3aa7cd78526c2a27699d1a17276ad94df7334a48c2676c0f8c3d5446
[root@docker ~]
[root@40c18d1c3aa7 haproxy]
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
69: eth0@if70: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:c0:a8:42:01 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 192.168.66.1/24 brd 192.168.66.255 scope global eth0
valid_lft forever preferred_lft forever
创建一个nginx容器
[root@docker ~]
7622549fd19d53557ac5beabea5a0cef2b9ade338d029abe079ecb3285432fb9
[root@docker ~]
[root@7622549fd19d /]
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
71: eth0@if72: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:c0:a8:42:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 192.168.66.2/24 brd 192.168.66.255 scope global eth0
valid_lft forever preferred_lft forever
创建一个httpd容器
[root@docker ~]
e74dbf195ec2e617db8656e528939afd3991192e468f640f84362242013656e7
[root@docker ~]
[root@e74dbf195ec2 src]
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
73: eth0@if74: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:c0:a8:42:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 192.168.66.3/24 brd 192.168.66.255 scope global eth0
valid_lft forever preferred_lft forever
访问
[root@docker ~]
我是徐猛他爹
<html><body><h1>It works!</h1></body></html>
我是徐猛他爹
<html><body><h1>It works!</h1></body></html>
我是徐猛他爹
<html><body><h1>It works!</h1></body></html>
我是徐猛他爹
<html><body><h1>It works!</h1></body></html>
我是徐猛他爹
<html><body><h1>It works!</h1></body></html>
|