//下载三个包
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz https://downloads.apache.org/httpd/httpd-2.4.53.tar.gz
[root@localhost ~]# docker rmi -f xz/httpd:a1.1
Untagged: xz/httpd:a1.1
Deleted: sha256:da5ece9c07c826c4e3067f47a505808b3c584cdfae7be823a6e027ac5b61ef34
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 5d0da3dc9764 7 months ago 231MB
[root@localhost ~]# docker run -it --name xz centos /bin/bash
[root@8682cfca7009 /]# ls
bin etc lib lost+found mnt proc run srv tmp var
dev home lib64 media opt root sbin sys usr
[root@8682cfca7009 /]# alias ls='ls --color' //有颜色
[root@8682cfca7009 /]# ls
bin etc lib lost+found mnt proc run srv tmp var
dev home lib64 media opt root sbin sys usr
[root@8682cfca7009 /]# cd /usr/src/ //包需要传到这个位置
[root@8682cfca7009 src]# ls
debug kernels
[root@localhost ~]# mkdir software //创建一个目录方便传软件
[root@localhost ~]# mv *.gz software/
[root@localhost ~]# ls
anaconda-ks.cfg software
[root@localhost ~]# docker cp software xz:/usr/src/ //吧这个包cp到容器里面
[root@8682cfca7009 src]# ls
debug kernels software
[root@8682cfca7009 src]# ls software/
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.53.tar.gz
[root@8682cfca7009 src]# ls -l software/
total 11116
-rw-r--r--. 1 root root 1093896 Jul 6 2020 apr-1.7.0.tar.gz
-rw-r--r--. 1 root root 554301 Jul 6 2020 apr-util-1.6.1.tar.gz
-rw-r--r--. 1 root root 9726558 Mar 14 09:45 httpd-2.4.53.tar.gz
[root@8682cfca7009 software]# tar xf apr-1.7.0.tar.gz
[root@8682cfca7009 software]# tar xf apr-util-1.6.1.tar.gz
[root@8682cfca7009 software]# tar xf httpd-2.4.53.tar.gz
[root@8682cfca7009 software]# ls
apr-1.7.0 apr-util-1.6.1 httpd-2.4.53
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.53.tar.gz
[root@8682cfca7009 apr-1.7.0]# cd /etc/yum.repos.d/
[root@8682cfca7009 yum.repos.d]# ls
CentOS-Linux-AppStream.repo
CentOS-Linux-BaseOS.repo
CentOS-Linux-ContinuousRelease.repo
CentOS-Linux-Debuginfo.repo
CentOS-Linux-Devel.repo
CentOS-Linux-Extras.repo
CentOS-Linux-FastTrack.repo
CentOS-Linux-HighAvailability.repo
CentOS-Linux-Media.repo
CentOS-Linux-Plus.repo
CentOS-Linux-PowerTools.repo
CentOS-Linux-Sources.repo
[root@8682cfca7009 yum.repos.d]# rm -rf * /需要配置阿里源,所以要把本地源都删了
[root@8682cfca7009 yum.repos.d]# ls
[root@8682cfca7009 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo //配置阿里centos源
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--100 2495 100 2495 0 0 3240 0 --:--:-- --:--:-- --:--:-- 3240
[root@8682cfca7009 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo //删除云相关
[root@8682cfca7009 yum.repos.d]# ls
CentOS-Base.repo
[root@8682cfca7009 ~]# dnf clean all
Failed to set locale, defaulting to C.UTF-8
0 files removed
[root@8682cfca7009 ~]# dnf makecache
Failed to set locale, defaulting to C.UTF-8
CentOS-8.5.2111 - Base - mirrors.ali 376 kB/s | 4.6 MB 00:12
CentOS-8.5.2111 - Extras - mirrors.a 24 kB/s | 10 kB 00:00
CentOS-8.5.2111 - AppStream - mirror 230 kB/s | 8.4 MB 00:37
Metadata cache created.
[root@8682cfca7009 ~]# cd /usr/src/software/apr-1.7.0
[root@8682cfca7009 apr-1.7.0]# ls
CHANGES apr.pc.in emacs-mode passwd
CMakeLists.txt apr.spec encoding poll
LICENSE atomic file_io random
Makefile.in build helpers shmem
Makefile.win build-outputs.mk include strings
NOTICE build.conf libapr.dep support
NWGNUmakefile buildconf libapr.dsp tables
README config.layout libapr.mak test
README.cmake config.log libapr.rc threadproc
apr-config.in config.nice locks time
apr.dep configure memory tools
apr.dsp configure.in misc user
apr.dsw docs mmap
apr.mak dso network_io
[root@8682cfca7009 apr-1.7.0]# dnf -y install gcc make
[root@8682cfca7009 apr-1.7.0]# ls
CHANGES apr.mak emacs-mode network_io
CMakeLists.txt apr.pc.in encoding passwd
LICENSE apr.spec file_io poll
Makefile.in atomic helpers random
Makefile.win build include shmem
NOTICE build-outputs.mk libapr.dep strings
NWGNUmakefile build.conf libapr.dsp support
README buildconf libapr.mak tables
README.cmake config.layout libapr.rc test
apr-config.in configure locks threadproc
apr.dep configure.in memory time
apr.dsp docs misc tools
apr.dsw dso mmap user
[root@8682cfca7009 apr-1.7.0]# vi configure
# $RM "$cfgfile" //注释或删除
[root@8682cfca7009 apr-1.7.0]# make
[root@8682cfca7009 apr-1.7.0]# make install
[root@8682cfca7009 apr-1.7.0]# cd ../apr-util-1.6.1
[root@8682cfca7009 apr-util-1.6.1]# dnf -y install expat-devel
[root@8682cfca7009 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@8682cfca7009 apr-util-1.6.1]# make
[root@8682cfca7009 apr-util-1.6.1]# make install
[root@8682cfca7009 apr-util-1.6.1]# cd ../httpd-2.4.53
[root@8682cfca7009 httpd-2.4.53]# ls
ABOUT_APACHE CMakeLists.txt InstallBin.dsp README
acinclude.m4 config.layout LAYOUT README.CHANGES
Apache-apr2.dsw configure libhttpd.dep README.cmake
Apache.dsw configure.in libhttpd.dsp README.platforms
apache_probes.d docs libhttpd.mak ROADMAP
ap.d emacs-style LICENSE server
build httpd.dep Makefile.in srclib
BuildAll.dsp httpd.dsp Makefile.win support
BuildBin.dsp httpd.mak modules test
buildconf httpd.spec NOTICE VERSIONING
CHANGES include NWGNUmakefile
changes-entries INSTALL os
[root@8682cfca7009 httpd-2.4.53]# useradd -r -M -s /sbin/nologin apache
[root@8682cfca7009 httpd-2.4.53]# dnf -y install pcre-devel
[root@8682cfca7009 httpd-2.4.53]# dnf -y install openssl-devel
[root@8682cfca7009 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@8682cfca7009 httpd-2.4.53]# make
[root@8682cfca7009 httpd-2.4.53]# make install
制作镜像
[root@localhost ~]# docker commit -a 'sean <1@2.com>' -c 'CMD ["/usr/local/apache/bin/httpd","-D","FOREGROUND"]' -p xz httpd:v0.1
sha256:8e0e272cc6816d514a4fb5641ff8897dcddcbcda13e591e32d5ed6be0ab90a33
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd v0.1 8e0e272cc681 15 seconds ago 616MB
centos latest 5d0da3dc9764 7 months ago 231MB
[root@localhost ~]# docker run -d --name web -p 80:80 httpd:v0.1
a046bf0541705b98cf6e09e8370889ade32b9886333507a850de1ce244089b3c
[root@localhost ~]# docker inspect web | grep "IPAddress"
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.3",
"IPAddress": "172.17.0.3",
[root@localhost ~]# curl 172.17.0.3
It works!
把不重要的删除
[root@8682cfca7009 ~]# cd /var [root@8682cfca7009 var]# du -sh * 0 adm 26M cache 0 crash 0 db 0 empty 0 ftp 0 games 0 gopher 0 kerberos 25M lib 0 local 0 lock 1.7M log 0 mail 0 nis 0 opt 0 preserve 0 run 0 spool 0 tmp 0 yp [root@8682cfca7009 var]# cd cache/ [root@8682cfca7009 cache]# ls bpf dnf ldconfig private [root@8682cfca7009 cache]# rm -rf * [root@8682cfca7009 cache]# ls [root@8682cfca7009 cache]# cd .. [root@8682cfca7009 var]# cd .. [root@8682cfca7009 /]# du -sh * 0 bin 0 dev 2.4M etc 0 home 0 lib 0 lib64 0 lost+found 0 media 0 mnt 0 opt du: cannot access 'proc/34288/task/34288/fd/4': No such file or directory du: cannot access 'proc/34288/task/34288/fdinfo/4': No such file or directory du: cannot access 'proc/34288/fd/4': No such file or directory du: cannot access 'proc/34288/fdinfo/4': No such file or directory 0 proc 32K root 4.0K run 0 sbin 0 srv 0 sys 12K tmp 537M usr 27M var [root@8682cfca7009 /]# cd usr/ [root@8682cfca7009 usr]# du -sh * 36M bin 0 games 14M include 41M lib 126M lib64 56M libexec 47M local 11M sbin 59M share 151M src 0 tmp [root@8682cfca7009 usr]# cd src/ [root@8682cfca7009 src]# ls debug kernels software [root@8682cfca7009 src]# rm -rf software/ //软件已经安装好了,软件包不需要可以删除 [root@8682cfca7009 src]# ls debug kernels [root@8682cfca7009 src]# cd .. [root@8682cfca7009 usr]# du -sh * 36M bin 0 games 14M include 41M lib 126M lib64 56M libexec 47M local 11M sbin 59M share 0 src 0 tmp [root@8682cfca7009 usr]# dnf -y remove gcc make //已经编译好了,不需要了也可以删除
删除完成后重新做一个版本的镜像,发现内存会小很多
[root@localhost ~]# docker commit -a 'sean <1@2.com>' -c 'CMD ["/usr/local/apache/bin/httpd","-D","FOREGROUND"]' -p xz httpd:v0.2 sha256:3fa1393d62d87b5052251650bbfa17daa598c1d2d871ad9c3b31ae57b80108a5 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE httpd v0.2 3fa1393d62d8 10 seconds ago 354MB httpd v0.1 8e0e272cc681 22 minutes ago 616MB centos latest 5d0da3dc9764 7 months ago 231MB



