dockerfile基于alpine系统构建haproxy镜像
运行两个容器测试
//运行apache容器
[root@localhost ~]# docker run -it -d --name httpd httpd:latest
Unable to find image 'httpd:latest' locally
latest: Pulling from library/httpd
e5ae68f74026: Already exists
bc36ee1127ec: Pull complete
d3576f2b6317: Pull complete
f1aa5f54b226: Pull complete
aa379c0cedc2: Pull complete
Digest: sha256:fba8a9f4290180ceee5c74638bb85ff21fd15961e6fdfa4def48e18820512bb1
Status: Downloaded newer image for httpd:latest
ea2372942b7ee33d9de50f31a825281da47b8a54fd39206067e2e5a14732595e
//访问页面内容
[root@localhost ~]# curl 172.17.0.2
<html><body><h1>It works!</h1></body></html>
//运行nginx容器
[root@localhost ~]# docker run -it -d --name nginx nginx
3aeb5b2f31dbde47c2dedc51b17c596d7a51d445e663ab9aa7efd713fa8f0794
//访问页面内容
[root@localhost ~]# curl 172.17.0.3
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...省略
构建haproxy镜像
//目录树
[root@localhost ~]# tree haproxy/
haproxy/
├── Dockerfile
├── entrypoint.sh
└── files
├── haproxy-2.5.0.tar.gz
└── install.sh
1 directory, 4 files
Dockerfile文件
[root@localhost ~]# cat haproxy/Dockerfile
FROM alpine
LABEL MAINTAINER 'abc 1@2.com'
ENV version 2.5.0
ENV PATH /usr/local/haproxy/sbin:$PATH
COPY files /usr/src/
COPY entrypoint.sh /
RUN /usr/src/install.sh
EXPOSE 80 8189
WORKDIR /usr/local/haproxy
ENTRYPOINT /entrypoint.sh
编译安装脚本
[root@localhost ~]# cat haproxy/files/install.sh //给执行权限
#!/bin/sh //alpine系统无法执行bash脚本
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
apk update
apk add --no-cache -U make gcc pcre-dev bzip2-dev openssl-dev elogind-de