Docker 用centos 编译安装apache

Docker 用centos 编译安装apache

前提条件: 安装docker
如果想安装docker请查阅:安装docker

环境准备:centos8

  1. 拉取centos镜像
[root@lvs 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 ttq6 -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
./configure --prefix=/usr/local/apache --sysco-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

It works!

[root@lvs ~]# [root@lvs ~]# docker commit -p ttq6 //创建 sha256:ac2cf0f87374d4726a2e7b3631fbe0af711c965fcdeb3e2ec4c52cbd90d25fdd [root@lvs ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 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@lvs ~]# [root@lvs ~]# 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/ Username: 这里输入你容器的账号及密码 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@lvs ~]# docker push ttq6/ttq6:v0.1

你可能感兴趣的:(docker,centos,apache)