栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

基于Dockerfile制作apache镜像

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于Dockerfile制作apache镜像

文章目录
      • dockerfile部署
      • 编辑Dockerfile
      • 制作镜像
      • 上传镜像到dockerhub

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
               e10ac9c1306c   17 hours ago   231MB
               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
               e10ac9c1306c   17 hours ago   231MB
               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
               e10ac9c1306c   17 hours ago   231MB
               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
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/871106.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号