基于容器编译安装apache制作为镜像

[root@localhost ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest

[root@localhost ~]# docker run --name h1 -it centos
[root@ab6d553008f4 /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@ab6d553008f4 /]# cd /etc/yum.repos.d
[root@ab6d553008f4 yum.repos.d]# ls
CentOS-Linux-AppStream.repo	     CentOS-Linux-Debuginfo.repo  CentOS-Linux-FastTrack.repo	      CentOS-Linux-Plus.repo
CentOS-Linux-BaseOS.repo	     CentOS-Linux-Devel.repo	  CentOS-Linux-HighAvailability.repo  CentOS-Linux-PowerTools.repo
CentOS-Linux-ContinuousRelease.repo  CentOS-Linux-Extras.repo	  CentOS-Linux-Media.repo	      CentOS-Linux-Sources.repo
[root@ab6d553008f4 yum.repos.d]# rm -f *
[root@ab6d553008f4 yum.repos.d]# ls
[root@ab6d553008f4 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0   4835      0 --:--:-- --:--:-- --:--:--  4825
[root@ab6d553008f4 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@ab6d553008f4 yum.repos.d]# yum clean all
Failed to set locale, defaulting to C.UTF-8
0 files removed
[root@ab6d553008f4 yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@ab6d553008f4 yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@ab6d553008f4 yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@ab6d553008f4 yum.repos.d]# yum clean all
Failed to set locale, defaulting to C.UTF-8
18 files removed
[root@ab6d553008f4 yum.repos.d]# ls
CentOS-Base.repo  epel-modular.repo  epel-testing-modular.repo	epel-testing.repo  epel.repo
[root@ab6d553008f4 ~]# dnf makecache

httpd依赖于apr,apr-util,httpd三个包
包下载位置:apache.org
下载依赖的三个包

[root@ab6d553008f4 ~]#  dnf -y install wget   
[root@ab6d553008f4 ~]#  wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
[root@ab6d553008f4 ~]#  wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
[root@ab6d553008f4 ~]#  wget https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz
[root@ab6d553008f4 ~]#  yum -y install openssl-devel pcre-devel expat-devel libtool  make   //安装依赖包

安装开发环境

[root@ab6d553008f4 ~]#  yum groups mark install "Development Tools"     //安装开发工具包
[root@ab6d553008f4 ~]# useradd -r -M -s /sbin/nologin apache   //创建系统用户
[root@ab6d553008f4 ~]# id apache
uid=998(apache) gid=996(apache) groups=996(apache)

解压

[root@ab6d553008f4 ~]# ls
anaconda-ks.cfg  anaconda-post.log  apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.53.tar.gz  original-ks.cfg
[root@ab6d553008f4 ~]# tar -xf apr-1.7.0.tar.gz 
[root@ab6d553008f4 ~]# tar -xf apr-util-1.6.1.tar.gz 
[root@ab6d553008f4 ~]# tar -xf httpd-2.4.53.tar.gz 
[root@ab6d553008f4 ~]# ls
anaconda-ks.cfg    apr-1.7.0	     apr-util-1.6.1	    httpd-2.4.53	 original-ks.cfg
anaconda-post.log  apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.53.tar.gz

安装apr

[root@ab6d553008f4 ~]# cd apr-1.7.0
[root@ab6d553008f4 apr-1.7.0]# ls
apr-config.in  apr.pc.in   buildconf	     configure	   encoding    libapr.dsp  Makefile.in	 network_io	random	      support	  tools
apr.dep        apr.spec    build-outputs.mk  configure.in  file_io     libapr.mak  Makefile.win  NOTICE		README	      tables	  user
apr.dsp        atomic	   CHANGES	     docs	   helpers     libapr.rc   memory	 NWGNUmakefile	README.cmake  test
apr.dsw        build	   CMakeLists.txt    dso	   include     LICENSE	   misc		 passwd		shmem	      threadproc
apr.mak        build.conf  config.layout     emacs-mode    libapr.dep  locks	   mmap		 poll		strings       time
[root@ab6d553008f4 apr-1.7.0]# vim configure
#   $RM "$cfgfile"    //注释掉或者删除这一行
[root@ab6d553008f4 apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@ab6d553008f4 apr-1.7.0]# make & make install

安装apr-util

[root@ab6d553008f4 ~]# cd apr-util-1.6.1
[root@ab6d553008f4 apr-util-1.6.1]# ls
aprutil.dep	apu-config.in	  CHANGES	  dbd		     include	     LICENSE	   NWGNUmakefile    strmatch
aprutil.dsp	buckets		  CMakeLists.txt  dbm		     ldap	     Makefile.in   README	    test
aprutil.dsw	build		  config.layout   docs		     libaprutil.dep  Makefile.win  README.cmake     uri
aprutil.mak	build.conf	  configure	  encoding	     libaprutil.dsp  memcache	   README.FREETDS   xlate
apr-util.pc.in	buildconf	  configure.in	  export_vars.sh.in  libaprutil.mak  misc	   redis	    xml
apr-util.spec	build-outputs.mk  crypto	  hooks		     libaprutil.rc   NOTICE	   renames_pending
[root@ab6d553008f4 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@ab6d553008f4 apr-util-1.6.1]# make & make install

安装httpd

[root@ab6d553008f4 ~]# cd httpd-2.4.53
[root@ab6d553008f4 httpd-2.4.53]# ls
ABOUT_APACHE	 ap.d	       CHANGES		configure.in  httpd.mak       LAYOUT	    Makefile.in    os		     ROADMAP  VERSIONING
acinclude.m4	 build	       changes-entries	docs	      httpd.spec      libhttpd.dep  Makefile.win   README	     server
Apache-apr2.dsw  BuildAll.dsp  CMakeLists.txt	emacs-style   include	      libhttpd.dsp  modules	   README.CHANGES    srclib
Apache.dsw	 BuildBin.dsp  config.layout	httpd.dep     INSTALL	      libhttpd.mak  NOTICE	   README.cmake      support
apache_probes.d  buildconf     configure	httpd.dsp     InstallBin.dsp  LICENSE	    NWGNUmakefile  README.platforms  test
[root@ab6d553008f4 httpd-2.4.53]# ./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

[root@ab6d553008f4 httpd-2.4.53]# make & make install

设置环境变量

[root@ab6d553008f4 ~]#  echo 'export PATH=/usr/local/apache/bin:$PATH' >/etc/profile.d/apache.sh
[root@ab6d553008f4 ~]# source /etc/profile.d/apache.sh 
[root@ab6d553008f4 ~]# which httpd
/usr/local/apache/bin/httpd
[root@ab6d553008f4 ~]# which apachectl
/usr/local/apache/bin/apachectl

include头文件,拥有头文件需要做映射关系

[root@ab6d553008f4 ~]# ln -s /usr/local/apache/include /usr/include/apache

取消警示

[root@ab6d553008f4 ~]# vim /usr/local/apache/conf/httpd.conf
#ServerName www.example.com:80    //取消注释

设置开机自启

[root@ab6d553008f4 ~]# apachectl start
[root@ab6d553008f4 ~]# ss -antl 
State            Recv-Q           Send-Q                       Local Address:Port                       Peer Address:Port           Process           
LISTEN           0                128                                0.0.0.0:80                              0.0.0.0:*         
//设置httpd服务的启动脚本
[root@ab6d553008f4 ~]#  vi start.sh 
[root@ab6d553008f4 ~]# cat start.sh
#!/bin/sh

/usr/local/apache/bin/httpd 
/bin/bash
[root@ab6d553008f4 ~]#  chmod a+x start.sh
                   

制作镜像

[[root@localhost ~]# docker commit -p -c 'CMD ["/bin/bash" ,"/start.sh"]' ab6d553008f4  yyqxyyds/httpd:a1.1    
sha256:4c5042b7cfe46bbbd61f352932e1184d9d18bdab35110bd263e8fe7e824af0e9
[root@localhost ~]# docker images
REPOSITORY         TAG       IMAGE ID       CREATED          SIZE
yyqxyyds/httpd     a1.1      4c5042b7cfe4   6 seconds ago    729MB

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED       STATUS       PORTS     NAMES
ab6d553008f4   centos    "/bin/bash"   3 hours ago   Up 3 hours             h1
[root@localhost ~]# docker run -itd -p 80:80  --name 123 yyqxyyds/httpd:a1.1 /bin/bash    //用做好的镜像进入容器
06f8fa2ebc27b31cbe20e48bc321f15320efc4049f1aed36a41b2b82cb772f83
[root@localhost ~]# docker exec -it 123 /bin/bash
[root@06f8fa2ebc27 /]# ls


在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值