docker镜像
Docker容器制作apache镜像
//docker镜像的获取
[root@z ~]# docker pull centos
[root@z ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 5d0da3dc9764 10 months ago 231MB
//创建并启动容器
[root@z ~]# docker run -it --name b1 centos
[root@89a561928111 /]#
编译apache
//安装开发环境
[root@89a561928111 ~]# yum groups mark install "Development Tools"
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:00:38 ago on Tue Aug 9 01:48:41 2022.
Dependencies resolved.
=============================================================================
Package Architecture Version Repository Size
=============================================================================
Installing Groups:
Development Tools
Transaction Summary
=============================================================================
Is this ok [y/N]: y
Complete!
[root@89a561928111 ~]# yum -y install openssl-devel pcre-devel expat-devel libtool wget make
//下载并安装apr-1.4+和apr-util-1.4+
[root@89a561928111 ~]# wget https://mirrors.aliyun.com/apache/apr/apr-1.7.0.tar.gz
--2022-08-09 02:01:18-- https://mirrors.aliyun.com/apache/apr/apr-1.7.0.tar.gz
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 45.253.17.212, 45.253.17.216, 43.224.184.231, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|45.253.17.212|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1093896 (1.0M) [application/octet-stream]
Saving to: ‘apr-1.7.0.tar.gz’
apr-1.7.0.tar.gz 100%[================>] 1.04M 452KB/s in 2.4s
2022-08-09 02:01:21 (452 KB/s) - ‘apr-1.7.0.tar.gz’ saved [1093896/1093896]
[root@89a561928111 ~]# wget https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
--2022-08-09 02:02:09-- https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 43.224.184.230, 43.224.184.224, 43.224.184.226, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|43.224.184.230|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 554301 (541K) [application/octet-stream]
Saving to: ‘apr-util-1.6.1.tar.gz’
apr-util-1.6.1.tar. 100%[================>] 541.31K 446KB/s in 1.2s
2022-08-09 02:02:11 (446 KB/s) - ‘apr-util-1.6.1.tar.gz’ saved [554301/554301]
//解压apr apr-util
[root@89a561928111 ~]# tar -xf apr-1.7.0.tar.gz
[root@89a561928111 ~]# tar -xf apr-util-1.6.1.tar.gz
[root@89a561928111 ~]# ls
anaconda-ks.cfg apr-1.7.0 apr-util-1.6.1 original-ks.cfg
anaconda-post.log apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz
//编译apr apr-util
[root@89a561928111 ~]# cd apr-1.7.0
[root@89a561928111 apr-1.7.0]# vi configure
cfgfile=${ofile}T
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
#$RM "$cfgfile" //注释这行
[root@89a561928111 apr-1.7.0]# ./configure --prefix=/usr/local/apr
过程省略......
[root@89a561928111 apr-1.7.0]# make && make install
过程省略......
[root@89a561928111 ~]# cd apr-util-1.6.1
[root@89a561928111 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util
--with-apr=/usr/local/apr
过程省略......
[root@89a561928111 apr-util-1.6.1]# make && make install
过程省略......
//编译安装httpd
[root@89a561928111 ~]# wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.54.tar.gz
[root@89a561928111 ~]# tar xf httpd-2.4.54.tar.gz
[root@89a561928111 ~]# ls
anaconda-ks.cfg apr-1.7.0.tar.gz httpd-2.4.54
anaconda-post.log apr-util-1.6.1 httpd-2.4.54.tar.gz
apr-1.7.0 apr-util-1.6.1.tar.gz original-ks.cfg
[root@89a561928111 ~]# cd httpd-2.4.54
[root@89a561928111 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@89a561928111 httpd-2.4.54]# make && make install
过程省略......
//配置环境变量
[root@89a561928111 ~]# echo "export PATH=$PATH:/usr/local/apache/bin" > /etc/profile.d/httpd.sh
[root@89a561928111 ~]# source /etc/profile.d/httpd.sh
[root@89a561928111 ~]# which httpd
/usr/local/apache/bin/httpd
[root@89a561928111 local]# ln -s /usr/local/apache/include/ /usr/include/httpd
//启动apache
[root@89a561928111 apache]# apachectl
[root@89a561928111 apache]# 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@89a561928111 ~]# vi /usr/bin/httpd-start
#!/bin/bash
/usr/local/apache/bin/apachectl && /usr/bin/tail -f /usr/local/apache/logs/access_log
[root@89a561928111 ~]# chmod +x /usr/bin/httpd-start
[root@89a561928111 ~]#
//在创建镜像时,我们不能关闭容器,必须使其处于运行状态,所以我们必须要另起一个终端,然后执行
//创建镜像
[root@localhost ~]# docker commit -c 'CMD ["httpd-start"]' -p b1 zzking1/b1:v0.1
sha256:dc5ac069cc4d684c35158b0ed0e15f1dbbf82e4d3793520b1131b91c5f2ca7ce
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
zzking1/b1 v0.1 dc5ac069cc4d 13 seconds ago 672MB
busybox latest 7a80323521cc 11 days ago 1.24MB
centos latest 5d0da3dc9764 10 months ago 231MB
//登录docker账号
[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: zzking1
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 zzking1/b1:v0.1
The push refers to repository [docker.io/zzking1/b1]
dfe144c1ec63: Pushed
74ddd0ec08fa: Mounted from library/centos
v0.1: digest: sha256:8be21a7ab14c31634d0fe2bf2fb147b1cb3bb6e39957d5a515fc1525c9c01918 size: 742
//使用新生成的镜像创建容器
[root@localhost ~]# docker run -it -d --name web -p 80:80 zzking1/b1:v0.1
f74734862a66c0a0ad8f0c4fa796d5725ced3ec20ffdd031fed3b5cc3d84ec7b
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f74734862a66 zzking1/b1:v0.1 "httpd-start" 4 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp web
89a561928111 centos "/bin/bash" 26 hours ago Up 21 minutes b1
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!