构建haproxy镜像(基于alpine系统)

构建haproxy镜像(基于alpine系统),第1张

构建haproxy镜像(基于alpine系统)

拉取alpine系统镜像

[root@localhost ~]# docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
Digest: sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300
Status: Image is up to date for alpine:latest
docker.io/library/alpine:latest

[root@localhost docker]# tree haproxy/
haproxy/
├── conf
│   └── RSS
├── Dockerfile
└── files
    ├── entrypoint.sh
    ├── haproxy-2.4.9.tar.gz
    ├── haproxy.cfg
    ├── install.sh

编写dockerfile

[root@localhost docker]# vim haproxy/Dockerfile 
FROM alpine
  
LABEL MAINTAINER='neawalke 123456789@qq.com'

ENV version 2.4.9
ENV PATH /usr/local/harpoxy/sbin:$PATH

ADD files/haproxy-${version}.tar.gz /tmp/
ADD files/install.sh /tmp/
COPY files/entrypoint.sh /


RUN /tmp/install.sh


EXPOSE 80 8189
ENTRYPOINT ["/entrypoint.sh"]
~                               

安装脚本

[root@localhost docker]# cat haproxy/files/install.sh 
#!/bin/sh
  
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories
apk update
adduser -S -H -s /sbin/nologin haproxy
addgroup haproxy
apk add --no-cache -U make gcc pcre-dev bzip2-dev openssl-dev elogind-dev libc-dev dahdi-tools dahdi-tools-dev libexecinfo libexecinfo-dev ncurses-dev zlib-dev zlib
cd /tmp/haproxy-${version}
make TARGET=linux-musl USE_OPENSSL=1 USE_ZLIB=1 USE_PCRE=1
make install PREFIX=/usr/local/haproxy
apk del gcc make
mkdir /usr/local/haproxy/conf
rm -rf  /tmp/install.sh

启动脚本

[root@localhost ~]# vim /docker/haproxy/files/entrypoint.sh
#!/bin/sh

cat > /usr/local/haproxy/conf/haproxy.cfg <> /usr/local/haproxy/conf/haproxy.cfg << EOF
    server web$count $rs:80 check inter 2000 fall 5
EOF
let count++
done
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg -db
~                                                                               
# 构建镜像
[root@localhost docker]# docker build -t haproxy:v5.0 haproxy
 
#启动页面容器
[root@localhost ~]# docker run -d --name web1 neawalke/httpd:latest 
6a81a9963d31c1cecd4cf715985b3b3da1e596a41195edf854ce108c92cf6a4e
[root@localhost ~]# docker run -d --name web2 neawalke/nginx:v2.0 
6c698a936d98a19dbd004181b51e25a03eb10f3066091a1c8adf922a77e99725

[root@localhost ~]# cat /docker/haproxy/conf/RSS 
172.17.0.2
172.17.0.3

#启动容器
[root@localhost docker]# docker run -it --name test1 -p 80:80 -v /docker/haproxy/conf:/tmp haproxy:v5.0


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5665677.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存