目录
基于容器制作镜像
[root@localhost ~]# docker images //查看是否有centos镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 5d0da3dc9764 10 months ago 231MB
[root@localhost ~]# docker run -it --rm centos //进入容器
[root@8b8554796959 /]# ls
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[root@8b8554796959 /]# cd /etc/yum.repos.d/
[root@8b8554796959 yum.repos.d]# ls
CentOS-Linux-AppStream.repo CentOS-Linux-ContinuousRelease.repo CentOS-Linux-Devel.repo CentOS-Linux-FastTrack.repo CentOS-Linux-Media.repo CentOS-Linux-PowerTools.repo
CentOS-Linux-BaseOS.repo CentOS-Linux-Debuginfo.repo CentOS-Linux-Extras.repo CentOS-Linux-HighAvailability.repo CentOS-Linux-Plus.repo CentOS-Linux-Sources.repo
[root@8b8554796959 yum.repos.d]# rm -rf *
[root@8b8554796959 yum.repos.d]# ls
[root@8b8554796959 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo //下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2495 100 2495 0 0 12794 0 --:--:-- --:--:-- --:--:-- 12794
[root@8b8554796959 yum.repos.d]# ls
CentOS-Base.repo
[root@8b8554796959 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@8b8554796959 yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm //下载新repo 到/etc/yum.repos.d/
Failed to set locale, defaulting to C.UTF-8
CentOS-8.5.2111 - Base - mirrors.aliyun.com 2.2 MB/s | 4.6 MB 00:02
CentOS-8.5.2111 - Extras - mirrors.aliyun.com 48 kB/s | 10 kB 00:00
[root@8b8554796959 yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@8b8554796959 yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel* //将 repo 配置中的地址替换为阿里云镜像站地址
[root@8b8554796959 yum.repos.d]# cd
[root@8b8554796959 ~]# dnf clean all //清理缓存
Failed to set locale, defaulting to C.UTF-8
18 files removed
[root@8b8554796959 ~]# dnf makecache
Failed to set locale, defaulting to C.UTF-8
CentOS-8.5.2111 - Base - mirrors.aliyun.com 1.9 MB/s | 4.6 MB 00:02
CentOS-8.5.2111 - Extras - mirrors.aliyun.com 24 kB/s | 10 kB 00:00
[root@8b8554796959 ~]# yum groups mark install 'Development Tools' //安装开发工具包
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:00:55 ago on Tue Aug 9 03:04:10 2022.
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Dependencies resolved.
=================================================================================================================================================================================================
Package Architecture Version Repository Size
=================================================================================================================================================================================================
Installing Groups:
Development Tools
Transaction Summary
=================================================================================================================================================================================================
Is this ok [y/N]: y
Complete!
[root@8b8554796959 ~]# useradd -r -M -s /sbin/nologin apache //安装用户和组
[root@8b8554796959 ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make vim wget //安装依赖包
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:01:47 ago on Tue Aug 9 03:04:10 2022.
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Dependencies resolved.
=================================================================================================================================================================================================
Package Architecture Version Repository 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
[root@8b8554796959 ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz //下载和安装apr以及apr-util
--2022-08-09 03:09:55-- https://downloads.apache.org/apr/apr-1.7.0.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 135.181.214.104, 2a01:4f9:3a:2c57::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|88.99.95.219|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1093896 (1.0M) [application/x-gzip]
Saving to: ‘apr-1.7.0.tar.gz’
apr-1.7.0.tar.gz 100%[=======================================================================================================>] 1.04M 15.1KB/s in 57s
[root@8b8554796959 ~]# ls
anaconda-ks.cfg anaconda-post.log apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz original-ks.cfg
[root@8b8554796959 ~]# tar xf apr-1.7.0.tar.gz
[root@8b8554796959 ~]# tar xf apr-util-1.6.1.tar.gz
[root@8b8554796959 ~]# ls
anaconda-ks.cfg anaconda-post.log apr-1.7.0 apr-1.7.0.tar.gz apr-util-1.6.1 apr-util-1.6.1.tar.gz original-ks.cfg
[root@8b8554796959 ~]# cd apr-1.7.0
[root@8b8554796959 apr-1.7.0]# ls
apr-config.in apr.mak build CHANGES configure.in encoding libapr.dep LICENSE memory NOTICE random strings threadproc
apr.dep apr.pc.in build.conf CMakeLists.txt docs file_io libapr.dsp locks misc NWGNUmakefile README support time
apr.dsp apr.spec buildconf config.layout dso helpers libapr.mak Makefile.in mmap passwd README.cmake tables tools
apr.dsw atomic build-outputs.mk configure emacs-mode include libapr.rc Makefile.win network_io poll shmem test user
[root@8b8554796959 apr-1.7.0]# vim configure
cfgfile=${ofile}T
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
# $RM "$cfgfile" //注释此行
[root@8b8554796959 apr-1.7.0]# ./configure --prefix=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
Configuring APR library
Platform: x86_64-pc-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.7.0
checking for chosen layout... apr
[root@8b8554796959 apr-1.7.0]# make && make install
make[1]: Entering directory '/root/apr-1.7.0'
/bin/sh /root/apr-1.7.0/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I./include -I/root/apr-1.7.0/include/arch/unix -I./include/arch/unix -I/root/apr-1.7.0/include/arch/unix -I/root/apr-1.7.0/include -I/root/apr-1.7.0/include/private -I/root/apr-1.7.0/include/private -o encoding/apr_encode.lo -c encoding/apr_encode.c && touch encoding/apr_encode.lo
/root/apr-1.7.0/build/mkdir.sh tools
/bin/sh /root/apr-1.7.0/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I./include -I/root/apr-1.7.0/include/arch/unix -I./include/arch/unix -I/root/apr-1.7.0/include/arch/unix -I/root/apr-1.7.0/include -I/root/apr-1.7.0/include/private -I/root/apr-1.7.0/include/private -o tools/gen_test_char.lo -c tools/gen_test_char.c && touch tools/gen_test_char.lo
[root@8b8554796959 apr-1.7.0]# cd ../apr-util-1.6.1
[root@8b8554796959 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking for working mkdir -p... yes
[root@8b8554796959 apr-util-1.6.1]# make && make install
make[1]: Entering directory '/root/apr-util-1.6.1'
/bin/sh /usr/local/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/root/apr-util-1.6.1/include -I/root/apr-util-1.6.1/include/private -I/usr/local/apr/include/apr-1 -o buckets/apr_brigade.lo -c buckets/apr_brigade.c && touch buckets/apr_brigade.lo
/bin/sh /usr/local/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/root/apr-util-1.6.1/include -I/root/apr-util-1.6.1/include/private -I/usr/local/apr/include/apr-1 -o buckets/apr_buckets.lo -c buckets/apr_buckets.c && touch buckets/apr_buckets.lo
[root@8b8554796959 ~]# wget https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz //编译安装httpd
--2022-08-09 03:17:20-- https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 135.181.214.104, 2a01:4f8:10a:201a::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|88.99.95.219|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9743277 (9.3M) [application/x-gzip]
Saving to: ‘httpd-2.4.54.tar.gz’
httpd-2.4.54.tar.gz 100%[=======================================================================================================>] 9.29M 16.0KB/s in 8m 31s
2022-08-09 03:25:52 (18.6 KB/s) - ‘httpd-2.4.54.tar.gz’ saved [9743277/9743277]
[root@8b8554796959 ~]# tar xf httpd-2.4.54.tar.gz
[root@8b8554796959 ~]# cd httpd-2.4.54
[root@8b8554796959 httpd-2.4.54]# ./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
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
[root@8b8554796959 httpd-2.4.54]# make && make install
Making all in srclib
make[1]: Entering directory '/root/httpd-2.4.54/srclib'
make[1]: Leaving directory '/root/httpd-2.4.54/srclib'
Making all in os
make[1]: Entering directory '/root/httpd-2.4.54/os'
Making all in unix
make[2]: Entering directory '/root/httpd-2.4.54/os/unix'
[root@8b8554796959 ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh //安装后配置
[root@8b8554796959 ~]# ls /usr/local/
apache apr apr-util bin etc games include lib lib64 libexec sbin share src
[root@8b8554796959 ~]# source /etc/profile.d/httpd.sh
[root@8b8554796959 ~]# which httpd
/usr/local/apache/bin/httpd
[root@8b8554796959 ~]# ls /usr/local/apache/
bin build cgi-bin conf error htdocs icons include logs man manual modules
[root@8b8554796959 ~]# ln -s /usr/local/apache/include /usr/include/apache
[root@8b8554796959 ~]# vim /usr/local/apache/conf/httpd.conf
ServerName www.example.com:80 //取消注释
[root@8b8554796959 ~]# apachectl start //启动
[root@8b8554796959 ~]# 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@8b8554796959 ~]# vim start.sh
#!/bin/sh
/usr/local/apache/bin/httpd
/bin/bash
[root@8b8554796959 ~]# chmod a+x start.sh //设置httpd服务的启动脚本
创建上传镜像
[root@localhost ~]# docker tag d381635935d0 zzh2002/httpd:v0.1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zzh2002/httpd 0.1 d381635935d0 3 minutes ago 682MB
centos latest 5d0da3dc9764 10 months ago 231MB
[root@localhost ~]# docker login
Login with your Docker ID 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.
Username: zzh2002
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@localhost ~]# docker push zzh2002/httpd:v0.1