Alpine制作httpd镜像

Alpine制作httpd镜像


基于Alpine镜像编写Dockerfile

项目目录
[root@loaclhost ~]# cd dockerfile_httpd/
[root@loaclhost dockerfile_httpd]# ls
Dockerfile  httpd  scripts
[root@loaclhost dockerfile_httpd]# tree 
.
├── Dockerfile
├── httpd
│   ├── apr-1.6.5.tar.gz
│   ├── apr-util-1.6.1.tar.gz
│   └── httpd-2.4.54.tar.gz
└── scripts
    └── entrypoint.sh
编写Dockerfile
[root@loaclhost dockerfile_httpd]# vim Dockerfile
# This is a Httpd image based on alpine
# Author zhangjunqiang


from alpine

LABEL MAINTAINER='zhangjunqiang 3318861575@qq.com'

ENV apr_version=1.6.5 apr_util_version=1.6.1 httpd_version=2.4.54
ENV PATH /usr/local/apache/bin:$PATH

ADD httpd/* /tmp/

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
    apk update && \
    apk add --no-cache -U gcc libc-dev expat-dev pcre-dev openssl-dev make && \
    cd /tmp && \
    cd /tmp/apr-${apr_version} && \
    sed -i '/$RM "$cfgfile"/d' configure &&\
    ./configure --prefix=/usr/local/apr && \
    make && make install && \
    cd /tmp/apr-util-${apr_util_version} && \
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && \
    make && make install && \
    cd /tmp/httpd-${httpd_version} && \
    ./configure --prefix=/usr/local/apache \
    --enable-so \
    --enable-ssl \
    --enable-cgi \
    --enable-rewrite \
    --with-zlib \
    --with-pcre \
    --with-apr=/usr/local/apr \
    --with-apr-util=/usr/local/apr-util/ \
    --enable-modules=most \
    --enable-mpms-shared=all \
    --with-mpm=prefork && \
    make && make install && \
    apk del gcc make && \
    rm -rf /var/cache/* && \
    rm -rf /tmp/*

WORKDIR /usr/local/apache

EXPOSE 80

CMD ["httpd","-D","FOREGROUND"]
创建和上传镜像
  • 创建镜像
[root@loaclhost dockerfile_httpd]# podman build -t httpd:v0.3.1 .
  • 测试镜像
[root@loaclhost dockerfile_httpd]# podman run -d --name web2 -P httpd:v0.
3.1 
f3ffc6f36d332aa3dc7d44be8346edb8b083613466430a88bb4da4191b042392
[root@loaclhost dockerfile_httpd]# podman inspect -l | grep -i ipadd
            "IPAddress": "10.88.0.6",
                    "IPAddress": "10.88.0.6",
[root@loaclhost dockerfile_httpd]# curl 10.88.0.6
<html><body><h1>It works!</h1></body></html>
  • 上传镜像
[root@loaclhost dockerfile_httpd]# podman tag httpd:v0.3.1 zjunwhite/httpd:v0.3.1
[root@loaclhost dockerfile_httpd]# podman save localhost/httpd:v0.3.1 -o httpd0.3.1.tar //压缩成tar包
[root@loaclhost ~]# docker load -i httpd.0.3.1.tar  //这里要用有docker的虚拟机上传,podman上传不能显示镜像大小,解压httpd镜像包
[root@localhost ~]# docker login
[root@localhost ~]# docker push zjunwhite/httpd:v0.3.1
[root@localhost ~]# docker logout 
Removing login credentials for https://index.docker.io/v1/

拓展部署网站

项目目录
[root@loaclhost alpine_httpd]# tree 
.
├── Dockerfile
└── files
    ├── apr-1.6.5.tar.gz
    ├── apr-util-1.6.1.tar.gz
    ├── chishenme.tar.gzc  //网站源码包
    └── httpd-2.4.54.tar.gz
编写Dockerfile
  1 # This is a Httpd image based on alpine
  2 # Author zhangjunqiang
  3 
  4 
  5 from alpine
  6 
  7 LABEL MAINTAINER='zhangjunqiang 3318861575@qq.com'
  8 
  9 ENV apr_version=1.6.5 apr_util_version=1.6.1 httpd_version=2.4.54
 10 ENV PATH /usr/local/apache/bin:$PATH
 11 
 12 ADD files/* /tmp/
 13 
 14 RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/r    epositories && \
 15     apk update && \
 16     apk add --no-cache -U gcc libc-dev expat-dev pcre-dev openssl-dev     make && \
 17     cd /tmp && \
 18     cd /tmp/apr-${apr_version} && \
 19     sed -i '/$RM "$cfgfile"/d' configure &&\
 20     ./configure --prefix=/usr/local/apr && \
 21     make && make install && \
 22     cd /tmp/apr-util-${apr_util_version} && \
 23     ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/ap    r && \
 24     make && make install && \
 25     cd /tmp/httpd-${httpd_version} && \
 26     ./configure --prefix=/usr/local/apache \
 27     --enable-so \
 28     --enable-ssl \
 29     --enable-cgi \
 30     --enable-rewrite \
 31     --with-zlib \
 32     --with-pcre \
 33     --with-apr=/usr/local/apr \
 34     --with-apr-util=/usr/local/apr-util/ \
 35     --enable-modules=most \
 36     --enable-mpms-shared=all \
 37     --with-mpm=prefork && \
 38     make && make install && \
 39     sed -i '/#ServerName/s/#//g' /usr/local/apache/conf/httpd.conf &&     \
 40     rm -f /usr/local/apache/htdocs/index.html && \
 41     mv /tmp/chishenme/* /usr/local/apache/htdocs/ && \
 42     apk del gcc make && \
 43     rm -rf /var/cache/* && \
 44     rm -rf /tmp/*
 45 
 46 WORKDIR /usr/local/apache
 47 
 48 EXPOSE 80
 49 
 50 CMD ["httpd","-D","FOREGROUND"]
创建镜像
[root@loaclhost alpine_httpd]# podman build -t httpd:v0.3.2 .
测试
[root@loaclhost alpine_httpd]# podman run -d --name web3 -P httpd:v0.3.2
28ac10d1899e11033d85907a9b93823a5a6e028577aa494793aef557012b5c11

在这里插入图片描述

上传至Docker Hub
[root@loaclhost alpine_httpd]# podman tag localhost/httpd:v0.3.2 zjunwhite/httpd:v0.3.2
[root@loaclhost alpine_httpd]# podman save localhost/httpd:v0.3.2 -o httpd0.3.2.tar  //压缩成tar包到有docker的虚拟机上传
Getting image source signatures
Copying blob 8d3ac3489996 done  
Copying blob 5a6c39057f66 done  
Copying blob f3751317b0ee done  
Copying config fd7ee17c48 done  
Writing manifest to image destination
Storing signatures
[root@loaclhost alpine_httpd]# ls
Dockerfile  files  httpd0.3.2.tar
[root@localhost ~]# docker load -i httpd.0.3.2.tar 
8d3ac3489996: Loading layer  5.866MB/5.866MB
5a6c39057f66: Loading layer  53.69MB/53.69MB
f3751317b0ee: Loading layer  63.47MB/63.47MB
Loaded image: localhost/httpd:v0.3.2
[root@localhost ~]# docker tag localhost/httpd:v0.3.2 zjunwhite/httpd:v0.3.2
[root@localhost ~]# docker login 
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: zjunwhite
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
[root@localhost ~]# docker push zjunwhite/httpd:v0.3.2 
The push refers to repository [docker.io/zjunwhite/httpd]
f3751317b0ee: Pushed 
5a6c39057f66: Pushed 
8d3ac3489996: Pushed 
v0.3.2: digest: sha256:011e6d0d077af405a2770ed58abdff0ecc3629ac169023be5f04123b22bdea0b size: 952
[root@localhost ~]# docker logout 
Removing login credentials for https://index.docker.io/v1/
y [docker.io/zjunwhite/httpd]
f3751317b0ee: Pushed 
5a6c39057f66: Pushed 
8d3ac3489996: Pushed 
v0.3.2: digest: sha256:011e6d0d077af405a2770ed58abdff0ecc3629ac169023be5f04123b22bdea0b size: 952
[root@localhost ~]# docker logout 
Removing login credentials for https://index.docker.io/v1/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

随便投投

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值