使用docker镜像搭建svn+Apache环境
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
環(huán)境準(zhǔn)備
虛擬機(jī)裝好之后,按照官網(wǎng)步驟檢查虛擬機(jī)內(nèi)核版本,必須在3.10以上版本,故此處安裝redhat_7.2
#?uname?-r 3.10.0-327.el7.x86_64安裝docker:
yum?install?docker-io有依賴是直接安裝具體的依賴軟件,解決依賴
docker安裝成功,啟動docker服務(wù)
service?docker?start并設(shè)置為開機(jī)自啟動
chkconfig?docker?on現(xiàn)在我們需要制作docker鏡像,可以通過Dockerfile或者是在現(xiàn)有的鏡像上修改之后commit。
此處選擇在現(xiàn)有的鏡像基礎(chǔ)上修改后commit并push到私有鏡像庫,以方便后期使用。
以下以Apache+svn(搭建svn環(huán)境)為例說明docker 鏡像的制作build、提交commit、上傳push過程?
一、獲取docker基礎(chǔ)鏡像
從docker公有庫down一個適合自己系統(tǒng)的鏡像(我此處down的是centos)
docker?pull?centos運(yùn)行down下來的docker容器:
docker?run?-it?centos?/bin/bash [root@84292236ae90?/]#進(jìn)入docker容器,進(jìn)行svn環(huán)境搭建,此處的?84292236ae90 即為你對于centos鏡像修改的ID,提交時只需要提交該ID的內(nèi)容即可。
二、在鏡像中安裝部署svn+Apache
此處使用yum安裝
yum -y install subversion?mod_dav_svn httpd
安裝成功后,配置初始化svn、用戶,權(quán)限(此處對于svn環(huán)境的搭建不做詳細(xì)的說明)
配置完成使用exit 退出docker容器
三、重啟Apache
為了使得docker容器可以使用宿主機(jī)的端口,此處映射宿主機(jī)的端口到docker容器
docker -p 參數(shù)把虛擬機(jī)的80端口映射到容器的80端口;虛擬機(jī)的80端口在 Vagrantfile 中被綁定到主機(jī)的8080端口,也就是:主機(jī)8080->虛擬機(jī)80->容器80
sudo docker run -t -i -p 80:80 -v /vagrant/htdocs:/var/www/html custom/httpd /bin/bash
# 啟動 Apache
apachectl -k start?
[root@bogon?svn_apache]#?sudo?docker?run?-t?-i?-p?80:80?-v?/vagrant/htdocs:/var/www/html?test?/bin/bash [root@84292236ae90?/]#?apachectl?-k?start Passing?arguments?to?httpd?using?apachectl?is?no?longer?supported. You?can?only?start/stop/restart?httpd?using?this?script. If?you?want?to?pass?extra?arguments?to?httpd,?edit?the /etc/sysconfig/httpd?config?file. [root@84292236ae90?/]#?ps?-ef|grep?httpd root?????????18??????1??7?18:44??????????00:00:00?/usr/sbin/httpd?-k?start svn??????????19?????18??0?18:44??????????00:00:00?/usr/sbin/httpd?-k?start svn??????????20?????18??0?18:44??????????00:00:00?/usr/sbin/httpd?-k?start svn??????????21?????18??0?18:44??????????00:00:00?/usr/sbin/httpd?-k?start svn??????????22?????18??0?18:44??????????00:00:00?/usr/sbin/httpd?-k?start svn??????????23?????18??0?18:44??????????00:00:00?/usr/sbin/httpd?-k?start root?????????25??????1??0?18:44??????????00:00:00?grep?--color=auto?httpd使用url訪問:
四、提交對鏡像所做的修改
docker?commit?-m?"Added?svn+apache"?-a?"yayad"?84292236ae90?centos-svn提交至本地的centos-svn鏡像,目前只存在于本機(jī)器,為了便于其他機(jī)器使用,需要提交至公有庫/私有個人庫,根據(jù)個人選擇。
此處我提交至個人私有庫:
1.找到本地鏡像的ID:docker images
[root@bogon?opt]#?docker?images REPOSITORY??????????TAG?????????????????IMAGE?ID????????????CREATED?????????????VIRTUAL?SIZE firstdocker?????????latest??????????????a3062f931635????????2?hours?ago?????????342.6?MB centos-svn??????????latest??????????????4dea4adb699d????????2?hours?ago?????????396.4?MB yayad/centos_svn????latest??????????????4dea4adb699d????????2?hours?ago?????????396.4?MB centos??????????????latest??????????????bb3d629a7cbc????????10?days?ago?????????196.6?MB2.docker tag <imageID> <namespace>/<image name>:<version tag eg latest>
docker?tag?4dea4adb699d?yayad/centos_svn3.push docker鏡像到官方的個人私有庫
docker?push?yayad/centos_svnpush時會提示輸入庫的賬號、密碼和郵箱,此處需要提前注冊docker.hub
push 成功后在個人私有庫即可看到push的鏡像
此時就可以在其他已經(jīng)安裝docker環(huán)境的機(jī)器上執(zhí)行docker pull centos-svn down該鏡像并直接使用svn環(huán)境,無需再安裝配置。
五、讓Apache服務(wù)在后臺自動running
但如何在啟動容器的同時自動啟動Apache服務(wù),不用再需要手動啟動,那么我就只需要在宿主機(jī)上監(jiān)控容器的狀態(tài)是否running,以下方式即可實(shí)現(xiàn)。
1.通過dockerfile 來build
編輯dockerfile
[root@bogon?svn_apache]#?cat?Dockerfile FROM?yayad/centos_svn ENTRYPOINT?apachectl?-k?start?&&?/bin/bashbuild 新image,設(shè)置tag為df
[root@bogon?svn_apache]#?docker?build?-t?yayad/centos_svn:df?. Sending?build?context?to?Docker?daemon?2.048?kB Sending?build?context?to?Docker?daemon Step?0?:?FROM?yayad/centos_svn--->?52561e4f9e39 Step?1?:?ENTRYPOINT?apachectl?-k?start?&&?/bin/bash--->?Running?in?30cab1c3a861--->?de5ad506e7dc Removing?intermediate?container?30cab1c3a861 Successfully?built?de5ad506e7dc查看build的image
[root@bogon?svn_apache]#?docker?images REPOSITORY??????????TAG?????????????????IMAGE?ID????????????CREATED?????????????VIRTUAL?SIZE yayad/centos_svn????df??????????????????de5ad506e7dc????????11?seconds?ago??????396.5?MB啟動容器查看配置結(jié)果
[root@bogon?svn_apache]#?docker?run?-it?yayad/centos_svn:df?/bin/bash Passing?arguments?to?httpd?using?apachectl?is?no?longer?supported. You?can?only?start/stop/restart?httpd?using?this?script. If?you?want?to?pass?extra?arguments?to?httpd,?edit?the /etc/sysconfig/httpd?config?file. Passing?arguments?to?httpd?using?apachectl?is?no?longer?supported. You?can?only?start/stop/restart?httpd?using?this?script. If?you?want?to?pass?extra?arguments?to?httpd,?edit?the /etc/sysconfig/httpd?config?file. httpd?(pid?9)?already?running [root@1dce83066942?/]#Apache服務(wù)已經(jīng)啟動起來了
2.修改容器的bashrc
這是投機(jī)取巧但不失為最簡單的一種辦法,見Run a service automatically in a docker container。
以bash啟動容器:
#docker?run?-it?-p?80:80?-v?/vagrant/htdocs:/var/www/html?yayad/centos_svn?/bin/bash [root@87da9f94dc08?/]#?vim?/etc/bashrc #add?by?dy????添加到最后 apachectl?-k?start若需要可以把修改后的image commit之后使用。
想提及一下的問題:刪除本地一些多余的名稱為NONE的images,報錯,刪除失敗,使用如下的方式解決了,但具體內(nèi)在聯(lián)系還不太清楚
docker?ps?-a?|?grep?"Exited"?|?awk?'{print?$1?}'|xargs?docker?stop docker?ps?-a?|?grep?"Exited"?|?awk?'{print?$1?}'|xargs?docker?rm docker?images|grep?none|awk?'{print?$3?}'|xargs?docker?rmi轉(zhuǎn)載于:https://my.oschina.net/u/2006667/blog/637882
總結(jié)
以上是生活随笔為你收集整理的使用docker镜像搭建svn+Apache环境的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Activiti Modeler发布以及
- 下一篇: 输入输出流(I/O)