Dockerfile_基于centos源码制作httpd镜像

Dockerfile_基于centos源码制作httpd镜像

1.项目目录(下载包)

[root@zwl packages]# ls
apr-1.6.5.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.54.tar.gz

2. **entrypoint.sh**脚本文件内容:

[root@zwl httpd]# cd scripts/
[root@zwl scripts]# ls
[root@zwl scripts]# touch entrypoint.sh
[root@zwl scripts]# ls
entrypoint.sh
[root@zwl scripts]# vim entrypoint.sh
[root@zwl scripts]# cat entrypoint.sh
#!/bin/bash

sed -i '/#ServerName/s/#//g' /usr/local/apache/conf/httpd.conf

exec "$@"
[root@zwl scripts]# chmod +x entrypoint.sh
[root@zwl scripts]# ll
total 4
-rwxr-xr-x. 1 root root 87 Aug 30 19:12 entrypoint.sh
[root@zwl scripts]#

3.基于centos制作httpd镜像的dockerfile

[root@zwl httpd]# vim Dockerfile
FROM centos

LABEL MAINTAINER='zhanwanli zhanwanli529@163.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 packages/httpd-${httpd_version}.tar.gz        /usr/src
ADD packages/apr-${apr_version}.tar.gz            /usr/src
ADD packages/apr-util-${apr_util_version}.tar.gz  /usr/src
ADD scripts/entrypoint.sh /

RUN rm -f /etc/yum.repos.d/* && \
    curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo && \
    sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo && \
    yum clean all && yum makecache && \
    yum -y install make gcc gcc-c++ openssl-devel pcre-devel expat-devel libtool libxml2-devel &&\
    useradd -r -M -s /sbin/nologin apache && \
    cd /usr/src/apr-${apr_version} &&\
    sed -i '/$RM "$cfgfile"/d' configure &&\
    ./configure --prefix=/usr/local/apr && \
    make && make install && \
    cd /usr/src/apr-util-${apr_util_version} &&\
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &&\
    make && make install &&\
    cd /usr/src/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 && \
    yum clean all && \
    yum -y remove gcc gcc-gcc+ make && \
    rm -rf /tmp/* /usr/src/*

WORKDIR /usr/local/apache

EXPOSE 80

CMD ["httpd","-D","FOREGROUND"]
ENTRYPOINT ["/bin/bash","/entrypoint.sh"]

4. 创建镜像

[root@zwl httpd]# podman build -t httpd:v0.4 .
..........
Successfully built 40b625d8c92b
Successfully tagged httpd:v0.4
[root@zwl httpd]# podman images
REPOSITORY       TAG       IMAGE ID       CREATED          SIZE
httpd            v0.4      40b625d8c92b   48 seconds ago   422MB
wanli123/httpd   v0.3      01569e7bc2f6   24 hours ago     695MB
centos           latest    5d0da3dc9764   11 months ago    231MB
[root@zwl httpd]#

5. 测试镜像

[root@zwl httpd]# podman run -d -P --name web1 httpd:v0.4
[root@zwl httpd]# podman ps
CONTAINER ID   IMAGE        COMMAND                  CREATED         STATUS         PORTS                                     NAMES
8dc590965472   httpd:v0.4   "/bin/bash /entrypoi…"   5 minutes ago   Up 5 minutes   0.0.0.0:49154->80/tcp, :::49154->80/tcp   web1
[root@zwl httpd]#
[root@zwl httpd]# podman inspect web1 | grep -i 'ipaddr'
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.2",
                    "IPAddress": "172.17.0.2",
[root@zwl httpd]# curl 172.17.0.2
<html><body><h1>It works!</h1></body></html>

在这里插入图片描述

6. 上传至docker hub

[root@zwl httpd]# podman tag httpd:v0.4 docker.io/wanli123/httpd:v0.4
[root@zwl httpd]# podman login docker.io
Authenticating with existing credentials...
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@zwl httpd]# podman images
REPOSITORY       TAG       IMAGE ID       CREATED          SIZE
httpd            v0.4      40b625d8c92b   14 minutes ago   422MB
wanli123/httpd   v0.4      40b625d8c92b   14 minutes ago   422MB
wanli123/httpd   v0.3      01569e7bc2f6   24 hours ago     695MB
centos           latest    5d0da3dc9764   11 months ago    231MB
[root@zwl httpd]# podman push wanli123/httpd:v0.4
The push refers to repository [docker.io/wanli123/httpd]
ce2a2c3e9ebe: Pushed
684654b2904e: Pushed
9968e7a6865c: Pushed
9cfa5d48e680: Pushed
c4febe6ebf23: Pushed
74ddd0ec08fa: Layer already exists
v0.4: digest: sha256:a5d7afec35716c6aecd4693353151e50d0c5eba64a08ec703941dc7ae0fbf69e size: 1580
[root@zwl httpd]#
[root@zwl httpd]# podman logout
Removing login credentials for https://index.docker.io/v1/

7. 下载测试

[root@zwl httpd]# podman images
REPOSITORY       TAG       IMAGE ID       CREATED          SIZE
httpd            v0.4      40b625d8c92b   26 minutes ago   422MB
wanli123/httpd   v0.4      40b625d8c92b   26 minutes ago   422MB
wanli123/httpd   v0.3      01569e7bc2f6   24 hours ago     695MB
centos           latest    5d0da3dc9764   11 months ago    231MB
[root@zwl httpd]# podman image rm httpd:v0.4
Untagged: httpd:v0.4
[root@zwl httpd]# podman image rm wanli123/httpd:v0.4
Untagged: wanli123/httpd:v0.4
Untagged: wanli123/httpd@sha256:a5d7afec35716c6aecd4693353151e50d0c5eba64a08ec703941dc7ae0fbf69e
Deleted: sha256:40b625d8c92b7d5e131ecc6d5e0110d1ef4c056c9ddc3f9d2980e9cc9973b6d1
Deleted: sha256:752194c44ce395da9588771b9de5c08db91b896ef9ba97db9b2dae1696d1fbda
Deleted: sha256:621f90450c618aa75abe85b3f00da6f93a530fcbb676fb5dd3970fa091d59380
Deleted: sha256:5d09599ba1bdbea08ff7d2026102dde43f3603e7144264eda1b43350aa01d5b4
Deleted: sha256:145fd4c85c8540008fd5d59a67ffcfb5fd01372d167e13826c96f37fc399b9a2
Deleted: sha256:2d24543b309465eae16ec38249bdcfae9a1de0e25c70f374ccbd1d7c240be274
Deleted: sha256:e3495e69106be62901ab0d289d51e7cfac97a6981e54f5812db102e4196d1fe1
Deleted: sha256:bb041cdb264595a508e4893e0f7393b08c74974a3cb89ef0e0c3c488be99693a
Deleted: sha256:2e817ab905beb86c0f027f467c4d0d5edbfe14b644d59e5c0a3193298fd222e8
Deleted: sha256:8e0f0db2b54beb9d9f4ef99d4fc9466921eb9cf64224144c9224a9275d7388b0
Deleted: sha256:a7d7f58d89188de6425bafb9d7ef0e829afb3d5744ac1568a65d2b42dcb00d51
Deleted: sha256:f117a3ea301645f9cee318a6a8b1bfbdb5973cd5678831b45a5e823a8554554b
Deleted: sha256:a6e2316f5e04ba1874374a153ceceac7734e67b272a9a8abc9a027a733a5124c
Deleted: sha256:0edad052b62150134b63d5602aba69f10e54b4ea0646b2fbced8d67d5be4bc14
Deleted: sha256:0850c2c11244bd0546c0ee0d9a0cd3e34bd5e611d18d6a91d9c3ff3ade805e72
Deleted: sha256:4403853817dbeaeb489bbe45529156b6db571a4d1c2b187a1cc7bf422aed3abe
Deleted: sha256:0f668946589d738290c5c819c37e7b6bd525d0cb811028c09490c9b6b22486b5
[root@zwl httpd]#
[root@zwl httpd]#
[root@zwl httpd]# podman images
REPOSITORY       TAG       IMAGE ID       CREATED         SIZE
wanli123/httpd   v0.3      01569e7bc2f6   24 hours ago    695MB
centos           latest    5d0da3dc9764   11 months ago   231MB
[root@zwl httpd]# podman pull docker.io/wanli123/httpd:v0.4
v0.4: Pulling from wanli123/httpd
a1d0c7532777: Already exists
b7a005b1fc7c: Pull complete
c1b07ebbd7b8: Pull complete
50ca0749528a: Pull complete
a5bb3e69231b: Pull complete
f5000660079d: Pull complete
Digest: sha256:a5d7afec35716c6aecd4693353151e50d0c5eba64a08ec703941dc7ae0fbf69e
Status: Downloaded newer image for wanli123/httpd:v0.4
docker.io/wanli123/httpd:v0.4
[root@zwl httpd]# podman images
REPOSITORY       TAG       IMAGE ID       CREATED          SIZE
wanli123/httpd   v0.4      40b625d8c92b   29 minutes ago   422MB
wanli123/httpd   v0.3      01569e7bc2f6   24 hours ago     695MB
centos           latest    5d0da3dc9764   11 months ago    231MB
[root@zwl httpd]# podman run -d -P --name web1 wanli123/httpd:v0.4
91d5c895a86e8b19a23a28f2b89d2e660b442642d3d78086d2a19aa7eadeee57
[root@zwl httpd]# podman ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS         PORTS                                     NAMES
91d5c895a86e   wanli123/httpd:v0.4   "/bin/bash /entrypoi…"   11 seconds ago   Up 9 seconds   0.0.0.0:49155->80/tcp, :::49155->80/tcp   web1
[root@zwl httpd]# podman inspect web1 | grep -i 'inaddr'
[root@zwl httpd]# podman inspect web1 | grep -i 'ipaddr'
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.2",
                    "IPAddress": "172.17.0.2",
[root@zwl httpd]# curl 172.17.0.2
<html><body><h1>It works!</h1></body></html>
[root@zwl httpd]#
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值