Docker 用centos 编译安装apache

Docker 用centos 编译安装apache

Docker 用centos 编译安装apache

前提条件: 安装docker

1.拉取centos镜像

//
[root@rl docker]# docker pull centos:8
8: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:8
docker.io/library/centos:8
[root@lvs docker]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       8         5d0da3dc9764   2 years ago    231MB

[root@lvs ~]# docker run --name rll6 -it centos
Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
[root@ce7828597669 /]# ls
bin  etc   lib	  lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr
[root@ce7828597669 /]# 

2. 进入容器操作

# 编译安装apache
[root@ce7828597669 ~]# cd /etc/yum.repos.d/
[root@ce7828597669 yum.repos.d]# rm -rf *
[root@ce7828597669 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@ce7828597669 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@ce7828597669 yum.repos.d]# yum clean all
[root@ce7828597669 yum.repos.d]# yum makecache
[root@ce7828597669 ~]# groupadd -r apache
[root@ce7828597669 ~]# useradd -r -M -s /sbin/nologin -g apache apache
[root@ce7828597669 ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
[root@ce7828597669 ~]# yum -y install gcc gcc-c++
[root@ce7828597669 src]# wget https://downloads.apache.org/apr/apr-1.7.4.tar.gz
[root@ce7828597669 src]#  wget https://downloads.apache.org/apr/apr-util-1.6.3.tar.gz
[root@ce7828597669 src]# wget http://archive.apache.org/dist/httpd/httpd-2.4.57.tar.gz
[root@ce7828597669 src]# ls 
apr-1.7.4.tar.gz  apr-util-1.6.3.tar.gz  debug	httpd-2.4.57.tar.gz  kernels
[root@ce7828597669 src]# tar xf apr-1.7.4.tar.gz 
[root@ce7828597669 src]# tar xf apr-util-1.6.3.tar.gz 
[root@ce7828597669 src]# tar xf httpd-2.4.57.tar.gz 
[root@ce7828597669 src]# ls
apr-1.7.4	  apr-util-1.6.3	 debug	       httpd-2.4.57.tar.gz
apr-1.7.4.tar.gz  apr-util-1.6.3.tar.gz  httpd-2.4.57  kernels
[root@ce7828597669 src]# cd apr-1.7.4
[root@ce7828597669 apr-1.7.4]# sed -i '/$RM "$cfgfile"/d' configure
[root@ce7828597669 apr-1.7.4]# ./configure --prefix=/usr/local/apr
[root@ce7828597669 apr-1.7.4]# make && make install
[root@ce7828597669 src]# cd apr-util-1.6.3
[root@ce7828597669 apr-util-1.6.3]#  ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@ce7828597669 apr-util-1.6.3]#  make && make install
[root@ce7828597669 httpd-2.4.57]# cd httpd-2.4.57
[root@ce7828597669 httpd-2.4.57]#./configure --prefix=/usr/local/apache \
--sysconfdir=/etc/httpd24 \
--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@ce7828597669 httpd-2.4.57]# make && make install
[root@ce7828597669 ~]#  echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh                              
[root@ce7828597669 ~]# source /etc/profile.d/httpd.sh
[root@ce7828597669 ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@ce7828597669 ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config
[root@ce7828597669 ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf
[root@ce7828597669 ~]# apachectl start
[root@ce7828597669 ~]# 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:*   
[root@lvs ~]# curl 172.17.0.2
<html><body><h1>It works!</h1></body></html>
[root@lvs ~]# 
[root@lvs ~]# docker commit -p ttq6  //创建
sha256:ac2cf0f87374d4726a2e7b3631fbe0af711c965fcdeb3e2ec4c52cbd90d25fdd
[root@lvs ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
<none>       <none>    ac2cf0f87374   15 seconds ago   745MB
httpd        latest    7f6a969e81a5   31 hours ago     168MB
centos       8         5d0da3dc9764   2 years ago      231MB
centos       latest    5d0da3dc9764   2 years ago      231MB
[root@lvs ~]# 
[root@lvs ~]# docker tag ac2cf0f87374 ttq6/ttq6:v0.1
[root@lvs ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
ttq6/ttq6    v0.1      ac2cf0f87374   2 minutes ago   745MB
httpd        latest    7f6a969e81a5   32 hours ago    168MB
centos       8         5d0da3dc9764   2 years ago     231MB
centos       latest    5d0da3dc9764   2 years ago     231MB
[root@rl ~]# 
[root@rl ~]# docker login
Log in with your Docker ID or email address 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.
You can log in with your password or a Personal Access Token (PAT). Using a limited-scope PAT grants better security and is required for organizations using SSO. Learn more at https://docs.docker.com/go/access-tokens/
下面输入容器账号和密码

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值