[root@localhost ~]# docker pull centos:88: Pulling from library/centos
a1d0c7532777: Pull complete
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:8
docker.io/library/centos:8
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 8 5d0da3dc9764 10 months ago 231MB
制作httpd容器
[root@localhost ~]# docker run -it --name httpd centos:8 /bin/bash[root@96d95580f706 /]# cd /etc/yum.repos.d/[root@96d95580f706 yum.repos.d]# rm -rf *[root@96d95580f706 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
00000000 --:--:-- --:--:-- --:--100 2495100249500108950 --:--:-- --:--:-- --:--:-- 10895[root@96d95580f706 yum.repos.d]# ls
CentOS-Base.repo
[root@96d95580f706 yum.repos.d]# yum clean all
Failed to set locale, defaulting to C.UTF-8
0 files removed
[root@96d95580f706 yum.repos.d]# yum makecache
Failed to set locale, defaulting to C.UTF-8
CentOS-8.5.2111 - Base - mirrors.ali 966 kB/s |4.6 MB 00:04
CentOS-8.5.2111 - Extras - mirrors.a 58 kB/s |10 kB 00:00
CentOS-8.5.2111 - AppStream - mirror 664 kB/s |8.4 MB 00:13
Metadata cache created.
[root@96d95580f706 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
//开启一个新终端,不要退出退出容器会停止
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
96d95580f706 centos:8 "/bin/bash"5 minutes ago Up 5 minutes httpd
//将源码包传到容器内
[root@localhost ~]# docker cp apr-1.7.0.tar.gz httpd:/root[root@localhost ~]# docker cp apr-util-1.6.1.tar.gz httpd:/root[root@localhost ~]# docker cp httpd-2.4.54.tar.gz httpd:/root#安装依赖包[root@96d95580f706 ~]# yum groups mark install 'Development Tools' -y[root@96d95580f706 ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make vim
编译httpd
[root@96d95580f706 ~]# useradd -r -M -s /sbin/nologin apache[root@96d95580f706 ~]# cd /root/[root@96d95580f706 ~]# ls
anaconda-ks.cfg apr-1.7.0.tar.gz httpd-2.4.54.tar.gz
anaconda-post.log apr-util-1.6.1.tar.gz original-ks.cfg
[root@96d95580f706 ~]# tar xf apr-1.7.0.tar.gz[root@96d95580f706 ~]# tar xf apr-util-1.6.1.tar.gz [root@96d95580f706 ~]# tar xf httpd-2.4.54.tar.gz [root@96d95580f706 ~]# cd apr-1.7.0[root@96d95580f706 apr-1.7.0]# vim configure
//搜索下面这条 注释掉 或者删除
$RM"$cfgfile"
//编译apr
[root@96d95580f706 apr-1.7.0]# ./configure --prefix=/usr/local/apr[root@96d95580f706 apr-1.7.0]# make && make install
//编译apr-util
[root@96d95580f706 apr-1.7.0]# cd [root@96d95580f706 ~]# cd apr-util-1.6.1[root@96d95580f706 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/[root@96d95580f706 apr-util-1.6.1]# make && make install
//编译httpd
[root@96d95580f706 httpd-2.4.54]# ./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@96d95580f706 httpd-2.4.54]# make && make install
设置环境变量
//环境变量
[root@96d95580f706 ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh[root@96d95580f706 ~]# source /etc/profile.d/apache.sh[root@96d95580f706 ~]# which httpd
/usr/local/apache/bin/httpd
[root@96d95580f706 ~]# which apachectl
/usr/local/apache/bin/apachectl
//软连接
[root@96d95580f706 ~]# ln -s /usr/local/apache/include/ /usr/include/apache[root@96d95580f706 ~]# vim /etc/httpd24/httpd.conf#ServerName www.example.com:80 // 此行取消注释[root@96d95580f706 ~]# apachectl start[root@96d95580f706 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 01280.0.0.0:80 0.0.0.0:*
[root@96d95580f706 ~]# vi start.sh[root@96d95580f706 ~]# cat start.sh#!/bin/sh
/usr/local/apache/bin/httpd
/bin/bash
[root@96d95580f706 ~]# chmod a+x start.sh
制作httpd镜像并创建一个能够访问web网站的容器
制作httpd的镜像
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
96d95580f706 centos:8 "/bin/bash"59 minutes ago Up 59 minutes httpd
[root@localhost ~]# docker commit -p -c 'CMD ["/bin/bash","/start.sh"]' 96d95580f706 chenlang123/httpd:v0.1
sha256:0a876bd309f11221bf200f01606f3d31a75a5c2be51df23fa28ab9ad2d69904d
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
chenlang123/httpd v0.1 0a876bd309f1 23 seconds ago 744MB
centos 8 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: chenlang123
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 chenlang123/httpd:v0.1
The push refers to repository [docker.io/chenlang123/httpd]
12da7c3b1809: Pushed
74ddd0ec08fa: Pushed
v0.1: digest: sha256:66462b764cd54659d99eae5c43000cab9b73d267ce275ba049d11877e38d0ab7 size: 742
[root@localhost ~]# docker pull chenlang123/httpd:v0.1
v0.1: Pulling from chenlang123/httpd
a1d0c7532777: Already exists
ea6686a0982d: Already exists
Digest: sha256:66462b764cd54659d99eae5c43000cab9b73d267ce275ba049d11877e38d0ab7
Status: Downloaded newer image for chenlang123/httpd:v0.1
docker.io/chenlang123/httpd:v0.1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
chenlang123/httpd v0.1 0a876bd309f1 4 hours ago 744MB
centos 8 5d0da3dc9764 10 months ago 231MB
[root@localhost ~]# docker run -dit -p 80:80 --name web chenlang123/httpd:v0.1 /bin/bash
679e17935af96b5488f157064c11263358e710bb35517c1570acb92c72c03619
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 01280.0.0.0:22 0.0.0.0:*
LISTEN 0128127.0.0.1:9000 0.0.0.0:*
LISTEN 01280.0.0.0:80 0.0.0.0:*
LISTEN 0128[::]:22 [::]:*
LISTEN 080 *:3306 *:*
LISTEN 0128[::]:80 [::]:*