[root@cxr ~]# docker run -tid --name httpd centos
2d693e16f4f3734b127cbae90d189c1b4e78619a54ceec912a82d96cf4f1c345
[root@cxr ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f300626d0336 centos "/bin/bash" 5 seconds ago Up 4 seconds httpd
// 连接上这个容器
[root@cxr ~]# docker exec -it 2d693e16f4f3 /bin/bash
[root@f300626d0336 /]#
// 把源码包放到容器中
[root@cxr ~]# docker cp /usr/src/apr-1.7.0.tar.gz f300626d0336:/usr/src/
[root@cxr ~]# docker cp /usr/src/apr-util-1.6.1.tar.gz f300626d0336:/usr/src/
[root@cxr ~]# docker cp /usr/src/httpd-2.4.53.tar.gzf300626d0336:/usr/src/
[root@f300626d0336 /]# ls /usr/src/
apr-1.7.0.tar.gz debug kernels
apr-util-1.6.1.tar.gz httpd-2.4.53.tar.gz
[root@f300626d0336 /]# useradd -r -M -s /sbin/nologin apache
[root@f300626d0336 /]# id apache
uid=998(apache) gid=996(apache) groups=996(apache)
[root@f300626d0336/]# yum groups mark install 'Development Tools' -y
yum groups mark install 'Development Tools'
Last metadata expiration check: 0:05:34 ago on Tue 26 Apr 2022 08:45:42 AM UTC.
Dependencies resolved.
=======================================================================
Package Architecture Version Repository Size
=======================================================================
Installing Groups:
Development Tools
Transaction Summary
=======================================================================
Is this ok [y/N]: y
Complete!
[root@f300626d0336 /]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make //安装过程省略一部分
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:03:22 ago on Tue Apr 26 08:45:42 2022
.
Dependencies resolved.
=======================================================================
Package Arch Version Repo Size
=======================================================================
Installing:
expat-devel x86_64 2.2.5-4.el8 base 55 k
gcc x86_64 8.5.0-4.el8_5 AppStream 23 M
gcc-c++ x86_64 8.5.0-4.el8_5 AppStream 12 M
libtool x86_64 2.4.6-25.el8 AppStream 709 k
openssl-devel x86_64 1:1.1.1k-5.el8_5 base 2.3 M
pcre-devel x86_64 8.42-6.el8 base 551 k
Upgrading:
glibc x86_64 2.28-164.el8 base 3.6 M
glibc-common x86_64 2.28-164.el8 base 1.3 M
glibc-minimal-langpack x86_64 2.28-164.el8 base 58 k
keyutils-libs x86_64 1.5.10-9.el8 base 34 k
krb5-libs x86_64 1.18.2-14.el8 base 840 k
libcom_err x86_64 1.45.6-2.el8 base 49 k
libgcc x86_64 8.5.0-4.el8_5 base 79 k
libsepol x86_64 2.9-3.el8 base 340 k
libstdc++ x86_64 8.5.0-4.el8_5 base 453 k
libxcrypt x86_64 4.1.1-6.el8 base 73 k
ncurses-base noarch 6.1-9.20180224.el8 base 81 k
ncurses-libs x86_64 6.1-9.20180224.el8 base 334 k
openssl-libs x86_64 1:1.1.1k-5.el8_5 base 1.5 M
pcre x86_64 8.42-6.el8 base 211 k
[root@f300626d0336 /]# cd /usr/src/
[root@f300626d0336 src]# tar xf apr-1.7.0.tar.gz -C /usr/local/
[root@f300626d0336 src]# tar xf apr-util-1.6.1.tar.gz -C /usr/local/
[root@f300626d0336 src]# tar xf httpd-2.4.53.tar.gz -C /usr/local/
[root@f300626d0336 src]# cd /usr/local/apr-1.7.0/
[root@f300626d0336 apr-1.7.0]# vi configure
cfgfile="${ofile}T"
trap "$RM "$cfgfile"; exit 1" 1 2 15
# $RM "$cfgfile" //将此行加上注释,或者删除此行
[root@f300626d0336 apr-1.7.0]# ./configure --prefix=/usr/local/apr //安装过程省略一部分
configure: creating ./config.status
config.status: creating Makefile
config.status: creating include/apr.h
config.status: creating build/apr_rules.mk
config.status: creating build/pkg/pkginfo
config.status: creating apr-1-config
config.status: creating apr.pc
config.status: creating test/Makefile
config.status: creating test/internal/Makefile
config.status: creating include/arch/unix/apr_private.h
config.status: executing libtool commands
config.status: executing default commands
[root@f300626d0336 apr-1.7.0]# make && make install //编译过程省略一部分
r/build-1; fi;
done
/usr/bin/install -c -m 755 /usr/local/apr-1.7.0/build/mkdir.sh /usr/local/apr/build-1
for f in make_exports.awk make_var_export.awk; do
/usr/bin/install -c -m 644 /usr/local/apr-1.7.0/build/${f} /usr/local/apr/build-1;
done
/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config
[root@f300626d0336 local]# cd apr-util-1.6.1/
[root@f300626d0336 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ //安装过程省略一部分
configure: creating ./config.status
config.status: creating Makefile
config.status: creating export_vars.sh
config.status: creating build/pkg/pkginfo
config.status: creating apr-util.pc
config.status: creating apu-1-config
config.status: creating include/private/apu_select_dbm.h
config.status: creating include/apr_ldap.h
config.status: creating include/apu.h
config.status: creating include/apu_want.h
config.status: creating test/Makefile
config.status: creating include/private/apu_config.h
config.status: executing default commands
[root@f30066d0336 apr-util-1.6.1]# make && make install //编译过程省略一部分
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1
-config
[root@f300626d0336 apr-util-1.6.1]# cd ../httpd-2.4.53/ //进入到httpd
[root@f300626d0336 httpd-2.4.49]# ./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 //安装过程省略一部分
Server Version: 2.4.53
Install prefix: /usr/local/apache
C compiler: gcc
CFLAGS: -g -O2 -pthread
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -E
[root@f300626d0336 httpd-2.4.49]# make && make install //编译省略一部分
Installing man pages and online manual
mkdir /usr/local/apache/man
mkdir /usr/local/apache/man/man1
mkdir /usr/local/apache/man/man8
mkdir /usr/local/apache/manual
make[1]: Leaving directory '/usr/local/httpd-2.4.53'
[root@f300626d0336 local]# echo 'exportPATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@f300626d0336 local]# source /etc/profile.d/httpd.sh
[root@f300626d0336 local]# ln -s /usr/local/apache/include /usr/include/apache
[root@f300626d0336 local]# apachectl start
[root@f300626d0336 local]# ss -anlt
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@f300626d0336 local]# cd /
[root@f300626d0336 /]#
[root@f300626d0336 /]#
[root@f300626d0336 /]# vi start.sh
#! /bin/sh
/usr/local/apache/bin/apachectl start
/bin/bash
[root@f300626d0336 /]# chmod +x start.sh
//构建镜像
[root@cxr ~]# docker commit -p -c 'CMD ["/bin/bash","start.sh"]' 2d693e16f4f3 chen1544060135/httpd:v0.1
sha256:16913ce01fdceee9a389906cf385893120734b1a088b894cc5dce1a9ead252fd
//打包成镜像包
[root@cxr ~]# docker save -o httpd.tar cxr1544060135/httpd:v0.1
[root@cxr ~]# ls
公共 模板 视频 图片 文档 下载 音乐 桌面 anaconda-ks.cfg httpd.tar initial-s
//scp命令发送给另外一台虚拟机
[root@cxr ~]# scp /root/httpd.tar 192.168.106.19:~/
The authenticity of host '192.168.106.19 (192.168.106.19)' can't be established.
ECDSA key fingerprint is SHA256:gEhvSbp/nEQlGHPUouJkP+ri9qPK7mu04QJWD8TW0+Q.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.106.19' (ECDSA) to the list of known hosts.
root@192.168.106.19's password:
httpd.tar 100% 704MB 78.6MB/s 00:08
//在另外一台虚拟机上解压
[root@localhost ~]# ls
anaconda-ks.cfg httpd.tar
[root@localhost ~]# docker load -i httpd.tar
74ddd0ec08fa: Loading layer [==================================================>] 238.6MB/238.6MB
7174f1d87286: Loading layer [==================================================>] 500.1MB/500.1MB
Loaded image: cxr1544060135/httpd:v0.1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
cxr1544060135/httpd v0.1 df7401555a16 About an hour ago 717MB
[root@localhost ~]# docker run --name web -it cxr1544060135/httpd:v0.1
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[root@129645bf8b13 /]# 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@129645bf8b13 /]# curl 172.17.0.2 //已经可以访问了
It works!