基于Dockerfile制作apache镜像

dockerfile部署

准备工作

[root@localhost ~]# mkdir apache
[root@localhost ~]# cd apache
[root@localhost apache]# mkdir files
[root@localhost apache]# cd files/
[root@localhost files]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz 
[root@localhost files]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
[root@localhost files]# wget https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz 
[root@localhost apache]# tree
.
├── Dockerfile
└── files
    ├── apr-1.7.0.tar.gz
    ├── apr-util-1.6.1.tar.gz
    └── httpd-2.4.53.tar.gz

1 directory, 4 files

编辑Dockerfile

[root@localhost apache]# vim Dockerfile
[root@localhost apache]# cat Dockerfile
FROM centos

LABEL MAINTAINER='jiuyue 1@2.com'

ENV apr_version=1.7.0 apr_util_version=1.6.1 httpd_version=2.4.53

ADD files/* /usr/src/

RUN rm -rf /etc/yum.repos.d/*
RUN 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 -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 &&\
    rm -rf /var/log/* /var/cache/* /usr/src/* && \
    dnf -y remove gcc gcc-c++ make


WORKDIR /usr/local/apache

EXPOSE 80

CMD ["-D","FOREGROUND"]

ENTRYPOINT ["/usr/local/apache/bin/apachectl']

制作镜像

[root@localhost ~]# docker build -t jiuyue99/httpd:latest  apache/
[root@localhost ~]# docker images
REPOSITORY       TAG       IMAGE ID       CREATED        SIZE
jiuyue/httpd     latest    3a47300e3d87   16 hours ago   717MB
<none>           <none>    e10ac9c1306c   17 hours ago   231MB
<none>           <none>    c0b8bc40ee00   17 hours ago   231MB
httpd            latest    dabbfbe0c57b   4 months ago   144MB
centos           latest    5d0da3dc9764   7 months ago   231MB

上传镜像到dockerhub

[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: jiuyue99
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 images
REPOSITORY       TAG       IMAGE ID       CREATED        SIZE
jiuyue/httpd     latest    3a47300e3d87   16 hours ago   717MB
<none>           <none>    e10ac9c1306c   17 hours ago   231MB
<none>           <none>    c0b8bc40ee00   17 hours ago   231MB
httpd            latest    dabbfbe0c57b   4 months ago   144MB
centos           latest    5d0da3dc9764   7 months ago   231MB
[root@localhost ~]# docker tag jiuyue/httpd jiuyue99/httpd:0505 
[root@localhost ~]# docker images
REPOSITORY       TAG       IMAGE ID       CREATED        SIZE
jiuyue99/httpd   0505      3a47300e3d87   16 hours ago   717MB
jiuyue/httpd     latest    3a47300e3d87   16 hours ago   717MB
<none>           <none>    e10ac9c1306c   17 hours ago   231MB
<none>           <none>    c0b8bc40ee00   17 hours ago   231MB
httpd            latest    dabbfbe0c57b   4 months ago   144MB
centos           latest    5d0da3dc9764   7 months ago   231MB

[root@localhost ~]# docker push jiuyue99/httpd:0505
The push refers to repository [docker.io/jiuyue99/httpd]
be9109f3ca37: Pushed 
01fd6df81c8e: Mounted from library/busybox 
042601: digest: sha256:f60d5819d04148e626a5c068c05f6991c86909eb4ef01b61b0aadcf9d903f50c size: 734
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值