docker容器源碼部署httpd用存儲(chǔ)卷部署網(wǎng)站(推薦)
docker容器源碼部署httpd,用存儲(chǔ)卷部署網(wǎng)站
創(chuàng)建一個(gè)httpd鏡像
// 創(chuàng)建一個(gè)httpd容器
[root@localhost ~]# docker run -tid --name httpd centos
2d693e16f4f3734b127cbae90d189c1b4e78619a54ceec912a82d96cf4f1c345
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2d693e16f4f3 centos "/bin/bash" 5 seconds ago Up 4 seconds httpd
// 連接上這個(gè)容器
[root@localhost ~]# docker exec -it 2d693e16f4f3 /bin/bash
[root@2d693e16f4f3 /]#
// 把源碼包放到容器中
[root@localhost ~]# docker cp /usr/src/apr-1.7.0.tar.gz 2d693e16f4f3:/usr/src/
[root@localhost ~]# docker cp /usr/src/apr-util-1.6.1.tar.gz 2d693e16f4f3:/usr/src/
[root@localhost ~]# docker cp /usr/src/httpd-2.4.49.tar.gz 2d693e16f4f3:/usr/src/
[root@2d693e16f4f3 /]# ls /usr/src/
apr-1.7.0.tar.gz debug kernels
apr-util-1.6.1.tar.gz httpd-2.4.49.tar.gz
// 源碼安裝httpd
[root@2d693e16f4f3 /]# useradd -r -M -s /sbin/nologin apache
[root@2d693e16f4f3 /]# id apache
uid=998(apache) gid=996(apache) groups=996(apache)
[root@2d693e16f4f3 /]# yum groups mark install 'Development Tools' -y
[root@2d693e16f4f3 /]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
[root@2d693e16f4f3 /]# cd /usr/src/
[root@2d693e16f4f3 src]# tar xf apr-1.7.0.tar.gz -C /usr/local/
[root@2d693e16f4f3 src]# tar xf apr-util-1.6.1.tar.gz -C /usr/local/
[root@2d693e16f4f3 src]# tar xf httpd-2.4.49.tar.gz -C /usr/local/
[root@2d693e16f4f3 src]# cd /usr/local/apr-1.7.0/
[root@2d693e16f4f3 apr-1.7.0]# vi configure
cfgfile="${ofile}T"
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
# $RM "$cfgfile" //將此行加上注釋?zhuān)蛘邉h除此行
[root@2d693e16f4f3 apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@2d693e16f4f3 apr-1.7.0]# make && make install
[root@2d693e16f4f3 local]# cd apr-util-1.6.1/
[root@2d693e16f4f3 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
[root@2d693e16f4f3 apr-util-1.6.1]# make && make install
[root@2d693e16f4f3 apr-util-1.6.1]# cd ../httpd-2.4.49/
[root@2d693e16f4f3 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
[root@2d693e16f4f3 httpd-2.4.49]# make && make install
[root@2d693e16f4f3 local]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@2d693e16f4f3 local]# source /etc/profile.d/httpd.sh
[root@2d693e16f4f3 local]# ln -s /usr/local/apache/include /usr/include/apache
[root@2d693e16f4f3 local]# apachectl start
[root@2d693e16f4f3 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@2d693e16f4f3 local]# cd /
[root@2d693e16f4f3 /]#
[root@2d693e16f4f3 /]#
[root@2d693e16f4f3 /]# vi start.sh
#! /bin/sh
/usr/local/apache/bin/apachectl start
/bin/bash
[root@2d693e16f4f3 /]# chmod +x start.sh
// 構(gòu)建鏡像
[root@localhost ~]# docker commit -p -c 'CMD ["/bin/bash","start.sh"]' 2d693e16f4f3 syblyw0806/httpd:v0.1
sha256:16913ce01fdceee9a389906cf385893120734b1a088b894cc5dce1a9ead252fd
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
syblyw0806/httpd v0.1 16913ce01fdc 6 seconds ago 713MB
busybox latest d23834f29b38 6 days ago 1.24MB
centos latest 5d0da3dc9764 2 months ago 231MB
部署nfs
需要開(kāi)啟一臺(tái)新的虛擬機(jī)
[root@localhost ~]# yum -y install nfs-utils [root@localhost ~]# systemctl restart nfs-server.service [root@localhost ~]# mkdir /nfs [root@localhost ~]# chmod 777 /nfs/ [root@localhost ~]# vim /etc/exports /nfs 192.168.200.136(rw) [root@localhost ~]# systemctl restart nfs-server
在有docker服務(wù)的虛擬機(jī)上一樣安裝nfs
[root@localhost ~]# yum -y install nfs-utils [root@localhost ~]# showmount -e 192.168.200.137 Export list for 192.168.200.137: /nfs 192.168.200.136
掛載
[root@localhost ~]# mount -t nfs 192.168.200.137:/nfs /var/www/html/ [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 883M 0 883M 0% /dev tmpfs 901M 0 901M 0% /dev/shm tmpfs 901M 8.9M 892M 1% /run tmpfs 901M 0 901M 0% /sys/fs/cgroup /dev/mapper/rhel-root 47G 23G 25G 48% / /dev/nvme0n1p1 1014M 179M 836M 18% /boot tmpfs 181M 0 181M 0% /run/user/0 overlay 47G 23G 25G 48% /var/lib/docker/overlay2/0a219b8bbb04290f6b1cc1ae29f5eb1a9bc713ff12c86c86c7e13d5c7ca63a0e/merged 192.168.200.137:/nfs 47G 2.2G 45G 5% /var/www/html
創(chuàng)建容器并映射
[root@localhost ~]# docker run -itd --name httpd1 -p 80:80 -v /var/www/html/:/usr/local/apache/htdocs 16913ce01fdc 42e38f1db61e49fafa0682125d0425e3d41c4f2db0f48e1973dee1905a90daf3 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 42e38f1db61e 16913ce01fdc "/bin/bash start.sh" 10 seconds ago Up 9 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp httpd1
上傳我們要部署網(wǎng)站的代碼
[root@localhost ~]# cd /var/www/html/ [root@localhost html]# ls game.html images index.html js style
此時(shí)在新開(kāi)的一臺(tái)虛擬機(jī)查看nfs
[root@localhost ~]# ls /nfs/ game.html images index.html js style
訪問(wèn)測(cè)試



到此這篇關(guān)于docker容器源碼部署httpd用存儲(chǔ)卷部署網(wǎng)站的文章就介紹到這了,更多相關(guān)docker容器部署httpd內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Docker部署.NET6項(xiàng)目的實(shí)現(xiàn)步驟
Docker是現(xiàn)在比較流行的開(kāi)源容器引擎,有了它讓我們部署和維護(hù)系統(tǒng)更加方便,本文主要介紹了Docker部署.NET6項(xiàng)目,具有一定的參考價(jià)值,感興趣的可以了解一下2023-12-12
Docker?鏡像構(gòu)建保姆級(jí)入門(mén)示例教程
Dockerfile?是一個(gè)用來(lái)構(gòu)建鏡像的文本文件,文本內(nèi)容包含了一條條構(gòu)建鏡像所需的指令和說(shuō)明,這篇文章主要介紹了Docker?鏡像構(gòu)建保姆級(jí)入門(mén)實(shí)戰(zhàn)指南,需要的朋友可以參考下2022-09-09
在Docker中安裝Oracle數(shù)據(jù)庫(kù)超詳細(xì)步驟
oracle作為全球最強(qiáng)大的關(guān)系型數(shù)據(jù)庫(kù),應(yīng)用在各行各業(yè),下面這篇文章主要給大家介紹了關(guān)于在Docker中安裝Oracle數(shù)據(jù)庫(kù)的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-01-01
Docker網(wǎng)絡(luò)原理及自定義網(wǎng)絡(luò)詳細(xì)解析
一般使用自定義網(wǎng)絡(luò),自定義網(wǎng)絡(luò)使用network創(chuàng)建,創(chuàng)建時(shí)可以指定子網(wǎng)網(wǎng)段及網(wǎng)關(guān)等信息,在創(chuàng)建并啟動(dòng)容器時(shí)指定使用的網(wǎng)絡(luò),今天通過(guò)本文給大家介紹Docker網(wǎng)絡(luò)原理及自定義網(wǎng)絡(luò)的相關(guān)知識(shí),感興趣的朋友一起看看吧2021-05-05
CentOS 7.x docker使用overlay2存儲(chǔ)方式
這篇文章主要介紹了CentOS 7.x docker使用overlay2存儲(chǔ)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11
3分鐘帶你學(xué)會(huì)docker搭建帕魯服務(wù)器
幻獸帕魯已經(jīng)正式開(kāi)服,目前在線人數(shù)已經(jīng)超過(guò)7W+,很多玩家想自己創(chuàng)建服務(wù)器和朋友一起聯(lián)機(jī)游玩,本文主要介紹了3分鐘帶你學(xué)會(huì)docker搭建帕魯服務(wù)器,具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01
使用docker -v 和 Publish over SSH插件實(shí)現(xiàn)war包自動(dòng)部署到docker的操作步驟
這篇文章主要介紹了利用docker -v 和 Publish over SSH插件實(shí)現(xiàn)war包自動(dòng)部署到docker的操作步驟,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-01-01
win7環(huán)境下Docker快速構(gòu)建及阿里云容器加速配置詳解
這篇文章主要介紹了win7環(huán)境下Docker快速構(gòu)建及阿里云容器加速配置詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09

