您好,登錄后才能下訂單哦!
這篇文章主要講解了“docker怎么配置python開發(fā)環(huán)境”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“docker怎么配置python開發(fā)環(huán)境”吧!
步驟:
1.安裝docker(這里不詳細(xì)介紹)
# 參考命令 sudo wget -qo- https://get.docker.com/ | sh
2.應(yīng)用目錄結(jié)構(gòu)
├──fanxiangce _docker ├── dockerfile ├── readme.md └─fanxiangce └──app ├── manage.py └── requirements ├── common.txt
3.編寫dockerfile(詳細(xì)命令解釋可以參考)
########################################################## # dockerfile to run a flask-based web application# based on an centos:7 image ########################################################## # set the base image to use to centos from centos:7 # set the file maintainer maintainer jasonwang,wjs7740@163.com # set env varibles used in this dockerfile (add a unique prefix, such as dockyard) # local directory with project source env dockyard_src=fanxiangce # directory in container for all project files env dockyard_srchome=/opt # directory in container for project source files env dockyard_srcproj=/opt/fanxiangce # update the defualt application repository source list run yum -y install epel-release run yum -y install python-pip run yum clean all # copy application source code to srcdir copy $dockyard_src $dockyard_srcproj # create application subdirectories workdir $dockyard_srcproj run mkdir log volume ['$dockyard_srcproj/log/'] # install python dependencies run pip install --upgrade pip run pip install -r $dockyard_srcproj/requirements/common.txt # port to expose expose 8000 # copy entrypoint script into the image workdir $dockyard_srcproj
4. build鏡像
# 在dockerfile同級目錄下 sudo docker build -t jason/webdemo .
成功后顯示successfully,同時(shí)返回鏡像id,如圖:
5.查看并啟動(dòng)鏡像
注意,此處-p映射的端口(主機(jī)端口:容器端口),容器端口應(yīng)與flask應(yīng)用定義的端口一致
sudo docker images sudo docker run -it --name webdemo -p 8000:8000 jason/webdemo /bin/bash
6.在容器中啟動(dòng)flask應(yīng)用
python manage.py runserver -p 8000
啟動(dòng)成功如下截圖:
7.在瀏覽器輸入127.0.0.1:8000即可訪問應(yīng)用
8.后續(xù)
如果容器關(guān)閉后需要再次進(jìn)入,可以用如下命令
# 查看當(dāng)前容器 sudo docker ps -a # 啟動(dòng)容器 docker start webdemo # 進(jìn)入容器 docker attach webdemo
感謝各位的閱讀,以上就是“docker怎么配置python開發(fā)環(huán)境”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對docker怎么配置python開發(fā)環(huán)境這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。