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 elog
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值