Dockerfile制作haproxy镜像

news/2024/6/3 17:54:37 标签: 容器, docker, dockerfile

Dockerfile制作haproxy镜像

结构目录

[root@localhost ~]# tree haproxy/
haproxy/
├── Dockerfile
└── files
    ├── haproxy-2.4.0.tar.gz
    ├── haproxy.cfg
    ├── install.sh
    ├── run_haproxy.sh
    └── sysctl.conf

1 directory, 6 files
[root@localhost ~]# 

Dockerfile文件内容

[root@localhost ~]# cd haproxy
[root@localhost haproxy]# cat Dockerfile 
FROM centos

ENV version 2.4.0
WORKDIR /usr/local
ADD files/haproxy${version}.tar.gz /usr/local/
ADD files/haproxy.sh /usr/local
ADD files/haproxy.cfg /etc/haproxy/
ADD files/run_haproxy.sh /usr/local
ADD files/sysctl.conf /etc/
RUN ["/bin/bash","-c","/usr/local/haproxy.sh"]

EXPOSE 80
CMD ["/usr/local/run_haproxy.sh"]

查看结构目录内容

[root@localhost ~]# cd haproxy/files/
[root@localhost files]# ls
haproxy-2.4.0.tar.gz  install.sh      sysctl.conf
haproxy.cfg           run_haproxy.sh
[root@localhost files]# cat install.sh 
#!/bin/bash 

rm -rf /etc/yum.repos.d/* 
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-$(awk -F'"' 'NR==2{print $2}' /etc/os-release).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-${version} 
make clean && \
make -j $(grep 'processor' /proc/cpuinfo |wc -l)  \
TARGET=linux-glibc  \
USE_OPENSSL=1  \
USE_ZLIB=1  \
USE_PCRE=1  \
USE_SYSTEMD=1  \
make install PREFIX=/usr/local/haproxy && \
cp haproxy  /usr/sbin/  && \
yum -y remove make gcc gcc-c++ && \
rm -rf /usr/src/haproxy-2.4.0
[root@localhost files]# 
[root@localhost files]# ls
haproxy-2.4.0.tar.gz  install.sh      sysctl.conf
haproxy.cfg           run_haproxy.sh
[root@localhost files]# cat sysctl.conf 
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1
[root@localhost files]# 
[root@localhost files]# ls
haproxy-2.4.0.tar.gz  install.sh      sysctl.conf
haproxy.cfg           run_haproxy.sh
[root@localhost files]# cat haproxy.cfg 
#--------------全局配置----------------
global
    log 127.0.0.1 local0  info
    #log loghost local0 info
    maxconn 20480
	#chroot /usr/local/haproxy
    pidfile /var/run/haproxy.pid
    #maxconn 4000
    user haproxy
    group haproxy
    daemon
#---------------------------------------------------------------------
#common defaults that all the 'listen' and 'backend' sections will
#use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode http
    log global
    option dontlognull
    option httpclose
    option httplog
    #option forwardfor
    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 hide-version
    stats admin if TRUE
    stats refresh 30s
#---------------web设置-----------------------
listen webcluster
    bind 0.0.0.0:80
    mode http
    #option httpchk GET /index.html
    log global
    maxconn 3000
    balance roundrobin
    cookie SESSION_COOKIE insert indirect nocache
    server web01 172.17.0.3:80 check inter 2000 fall 5
    server web02 172.17.0.4:80 check inter 2000 fall 5
    #server web01 192.168.80.102:80 cookie web01 check inter 2000 fall 5
[root@localhost files]# 
[root@localhost files]# cat run_haproxy.sh 
#!/bin/sh

haproxy -f /etc/haproxy/haproxy.cfg

/bin/bash
[root@localhost files]# 

制作haproxy镜像

[root@localhost haproxy]# docker build -t haproxy:v0.1 .
[root@localhost haproxy]# docker images
REPOSITORY         TAG       IMAGE ID       CREATED         SIZE
haproxy            v0.1      833130f07d74   4 seconds ago   578MB
1225514226/httpd   v0.4      37f8ea813545   47 hours ago    702MB
1225514226/httpd   v0.2      026478daf0c7   3 days ago      702MB
1225514226/nginx   v0.1      c98f0d7db627   6 days ago      579MB
busybox            latest    d23834f29b38   10 days ago     1.24MB
centos             latest    5d0da3dc9764   2 months ago    231MB
[root@localhost haproxy]# 

运行haproxy容器并映射端口

[root@localhost haproxy]# docker run -itd --name haproxy -p 1111:80 833130f07d74
03df66f57ac99f21891c5c14e992bed7e68da2869611a86e089c4b95dd794053
[root@localhost haproxy]# docker ps -a 
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                                   NAMES
03df66f57ac9   833130f07d74   "/usr/local/run_hapr…"   4 seconds ago   Up 3 seconds   0.0.0.0:1111->80/tcp, :::1111->80/tcp   haproxy
[root@localhost haproxy]# 
[root@localhost haproxy]# docker exec -it haproxy /bin/bash
[root@03df66f57ac9 local]# ss -antl
State           Recv-Q          Send-Q                   Local Address:Port                   Peer Address:Port          Process          
LISTEN          0               128                            0.0.0.0:80                          0.0.0.0:*                              
LISTEN          0               128                            0.0.0.0:8189                        0.0.0.0:*                              
[root@03df66f57ac9 local]# 

运行一个httpd镜像和nginx镜像

[root@localhost ~]# docker run -d --name httpd 1225514226/httpd:v0.4
636b41c7296b518a13b23b18b03a82887e2fa355b69e0a442e70a85f98d158b7
[root@localhost ~]# docker run -d --name nginx 1225514226/nginx:v0.1
199524481ed4e279bc2cc605b305be71bb7828ce4568efcaace59e149c8248ac
[root@localhost ~]# docker ps -a 
CONTAINER ID   IMAGE          COMMAND                  CREATED              STATUS                          PORTS                                   NAMES
199524481ed4   c98f0d7db627   "bin/bash start.sh"      About a minute ago   Exited (0) About a minute ago                                           nginx
636b41c7296b   37f8ea813545   "/usr/local/apache/b…"   About a minute ago   Up About a minute               80/tcp, 443/tcp                         httpd
03df66f57ac9   833130f07d74   "/usr/local/run_hapr…"   6 minutes ago        Up 6 minutes                    0.0.0.0:1111->80/tcp, :::1111->80/tcp   haproxy
[root@localhost ~]# 

访问测试

在这里插入图片描述
在这里插入图片描述


http://www.niftyadmin.cn/n/1032182.html

相关文章

揭开Unity AssetBundle庐山真面目(二)

原文链接:http://blog.uwa4d.com/archives/ABtopic_2.html 在之前的分享揭开AssetBundle庐山真面目(一)中,我们主要剖析了4.x版本下的AssetBundle管理机制,那5.x版本究竟有些什么变化呢?今天我们来一探究竟…

Dockerfile使用alpine系统制作haproxy镜像

Dockerfile使用alpine系统制作haproxy镜像 Dockerfile目录结构 [rootlocalhost haproxyalpine]# tree . ├── Dockerfile └── files├── haproxy-2.5.0.tar.gz├── haproxycfg.sh├── install.sh└── sysctl.confDockerfile [rootlocalhost haproxyalpine]# ca…

你应该知道的Unity AssetBundle管理机制

原文链接:http://blog.uwa4d.com/archives/ABTheory.html 接上期AssetBundle打包的讲解,我们今天为大家继续探秘AssetBundle,从管理机制的角度出发,谈谈其资源加载和卸载的原理。 AssetBundle加载基础 通过AssetBundle加载资源&am…

【Unity】好插件让你事半功倍!—资源篇

原文链接:http://blog.uwa4d.com/archives/Resource_Plugin.html 工欲善其事必先利其器。在Unity官网的Asset Store上有不少给力的资源插件,能帮助我们减少人力资源消耗的同时,更快更好地驾驭引擎。今天我们就从善用资源的角度,推…

【Unity】扒一扒Profiler中这几个“占坑鬼”

原文链接:http://blog.uwa4d.com/archives/presentandsync.html WaitForTargetFPS、Gfx.WaitForPresent 和 Graphics.PresentAndSync是我们经常会被问到的参数。想必正在读此文的你也经常在Profiler中遇到过这几项CPU开销过大的情况。对此,我们今天就来好…

私有仓库harbor部署

私有仓库Harbor部署 文章目录私有仓库Harbor部署Docker RegistryHarborHarbor部署:安装docker安装docker-compose搭建Harbor浏览器访问用户管理docker-compose控制容器Docker Registry 网上有很多的Registry服务器都支持第三方用户注册,而后基于用户名去…

【Unity】那些你不得不用的好插件!

原文链接:http://blog.uwa4d.com/archives/Plugins0323.html 继上期发分享:好插件让你事半功倍《资源篇》,本期我们就功能开发再给大家推荐几个非常省心的工具,侑虎君亲测有效! 在手机上插入电影已经是当下非常普及的需…

你的项目和大作只差一个插件的距离!

原文链接:http://blog.uwa4d.com/archives/567.html 本期我们来为美术设计师谋个福利,那些大片即视感是如何打造的?有没有一些插件能快速实现高逼格的效果呢?所以,巨人的肩膀来了,您可得踩稳了哦&#xff0…