07-docker系列-使用dockerfile構(gòu)建python、jenkins鏡像

聲明:本文乃“運(yùn)維家”原創(chuàng),轉(zhuǎn)載請(qǐng)注明出處,更多內(nèi)容請(qǐng)關(guān)注公眾號(hào)“運(yùn)維家”。

主旨

本文續(xù)接上一篇繼續(xù)使用dockerfile方式,分別構(gòu)建python、jenkins鏡像。

環(huán)境

linux環(huán)境docker環(huán)境python3.7.1?安裝包一個(gè),其他版本均可

下載軟件

python安裝包可以從官網(wǎng)下載,但是比較麻煩,且需要登錄,版本也比較凌亂,在這里小編提供一個(gè)3.7.1的python安裝包。關(guān)注公眾號(hào)“運(yùn)維家”,后臺(tái)回復(fù)“python安裝包”即可獲取下載鏈接。

python鏡像構(gòu)建

創(chuàng)建目錄,并切換至對(duì)應(yīng)目錄:

[yunweijia@localhost ~]$ mkdir -pv docker/pythonmkdir: 已創(chuàng)建目錄 "docker/python"[yunweijia@localhost ~]$ cd docker/python/[yunweijia@localhost python]$

上傳python3.7.1的軟件包:

[yunweijia@localhost python]$ pwd/home/yunweijia/docker/python[yunweijia@localhost python]$ lsinstall.sh  Python-3.7.1.tgz[yunweijia@localhost python]$

python安裝腳本:

[yunweijia@localhost python]$ pwd/home/yunweijia/docker/python[yunweijia@localhost?python]$?vim?install.sh?yum -y install -y tar libffi-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make initscriptscd /tmptar xf Python-3.7.1.tgzcd Python-3.7.1/./configure --prefix=/usr/local/python3 --enable-shared --with-sslmake && make install && make cleancd ~rm -rf /tmp/Python-3.7.1*mv /usr/bin/python /usr/bin/python27ln -s /usr/local/python3/bin/python3.7 /usr/bin/pythonln -s /usr/local/python3/bin/pip3.7 /usr/bin/pipecho "/usr/local/python3/lib" > /etc/ld.so.conf.d/python3.confldconfig[yunweijia@localhost python]$

dockerfile文件:

[yunweijia@localhost?python]$?vim?Dockerfile?FROM centos:7COPY Python-3.7.1.tgz /tmp/Python-3.7.1.tgzCOPY install.sh /tmp/install.shRUN sh /tmp/install.sh[yunweijia@localhost python]$

構(gòu)建python鏡像:

[yunweijia@localhost python]$ sudo docker build -t yunweijia:python3 /home/yunweijia/docker/python/#?直至出現(xiàn)如下信息Successfully built 31255eafafc3Successfully tagged yunweijia:python3[yunweijia@localhost?python]$?sudo?docker?imagesREPOSITORY   TAG       IMAGE ID       CREATED         SIZEyunweijia    python3   31255eafafc3   6 minutes ago   662MBcentos       7         eeb6ee3f44bd   5 months ago    204MB[yunweijia@localhost python]$

驗(yàn)證python鏡像:

[yunweijia@localhost python]$ sudo docker run -it yunweijia:python3 /bin/bash[root@57df1e69888d /]# python -VPython 3.7.1[root@57df1e69888d /]# pip -Vpip 10.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)[root@57df1e69888d /]# exitexit[yunweijia@localhost python]$

jenkins鏡像構(gòu)建

創(chuàng)建目錄,并切換至對(duì)應(yīng)目錄:

[yunweijia@localhost ~]$ mkdir -pv docker/jenkinsmkdir: 已創(chuàng)建目錄 "docker/jenkins"[yunweijia@localhost ~]$ cd docker/jenkins/[yunweijia@localhost jenkins]$

?jenkins安裝腳本:

[yunweijia@localhost jenkins]$ vim jenkins_install.sh yum -y install wget gccyum -y install initscriptstouch /etc/yum.repos.d/jenkins.repocat >> /etc/yum.repos.d/jenkins.repo << EOF[jenkins]name=Jenkins-stablebaseurl=http://pkg.jenkins.io/redhat-stablegpgcheck=1EOFrpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.keyyum -y upgradeyum -y install epel-release java-11-openjdk-develyum -y install jenkins[yunweijia@localhost jenkins]$   

dockerfile文件:

[yunweijia@localhost?jenkins]$?vim?Dockerfile?FROM centos:7COPY jenkins_install.sh /tmp/jenkins_install.shRUN sh /tmp/jenkins_install.sh[yunweijia@localhost jenkins]$

構(gòu)建jenkins鏡像:

[yunweijia@localhost jenkins]$ sudo docker build -t yunweijia:jenkins /home/yunweijia/docker/jenkins/

驗(yàn)證jenkins鏡像:

[yunweijia@localhost jenkins]$ sudo docker run -d yunweijia:jenkins /bin/bash -c "/etc/rc.d/init.d/jenkins start; while true;do echo yunweijia; sleep 5; done"c093cea8b3a43475428f022d3f4528c3ed0ef1bb4010dadb4025f3e4536a6465[yunweijia@localhost?jenkins]$?[yunweijia@localhost jenkins]$ sudo docker exec -it c093cea8b3a4 /bin/bash[root@c093cea8b3a4 /]# [root@c093cea8b3a4 /]# ps -ef | grep jenkinsroot          1      0  0 10:46 ?        00:00:00 /bin/bash -c /etc/rc.d/init.d/jenkins start; while true;do echo yunweijia; sleep 5; donejenkins      11      1 69 10:46 ?        00:00:14 /etc/alternatives/java -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -jar /usr/lib/jenkins/jenkins.war --logfile=/var/log/jenkins/jenkins.log --webroot=/var/cache/jenkins/war --httpPort=8080 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20root         83     64  0 10:46 pts/0    00:00:00 grep --color=auto jenkins[root@c093cea8b3a4 /]# exitexit[yunweijia@localhost jenkins]$

從上文和本文來看,使用dockerfile構(gòu)建鏡像是較為簡(jiǎn)單的一件事兒,但是需要我們不斷的練習(xí),至于如何在docker容器中安裝服務(wù),和直接在宿主機(jī)安裝服務(wù)是一樣的操作。

至此,本文結(jié)束。下一篇我們介紹下docker容器的網(wǎng)絡(luò)模式。

本文使用 文章同步助手 同步

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容