1. 程式人生 > >製作一個python-docker image and run a container!

製作一個python-docker image and run a container!

#docker pull holbertonschool/ubuntu-1404-python3
#docker run --name python3 -v /home:/mnt -ti docker.io/holbertonschool/ubuntu-1404-python3:latest  /bin/bash
安裝pip或是通過pip來安裝很不方便,放棄了!


我還是基於lnmpa3來增加redis-server/python3吧。這樣做一個docker image出來,方便以後部署使用。
centos7                                              lnmpa3              29325ac27e08        13 months ago       7.63 GB
真的是好大啊!
python的各個app應用,也要基於虛擬機器技術來進行,避免相互干擾。
# docker run --name python_app -v /home:/mnt -ti lnmpa3:centos7 /bin/bash//製作image,不要對映port
雖然大一點,但對redis和python進行make&&make install非常順利!!這也不容易!


提交修改,生成新的image:
#docker commit -m "lnmpa-python" -a "yingcai" python_app  python:lnmpa3
備份image先:
#docker save python:lnmpa3 > /home/backup/python_lnmpa3.tar
執行一個container:
#docker run --name python_app -p 8000:8000 -v /home:/mnt -ti python:lnmpa3 /bin/bash




問題1:
mysql-python安裝時EnvironmentError: mysql_config not found
解決:
#apt-get update
#apt-get install libmysqlclient-dev
# pip3 install mysqlclient 


問題2:執行django執行新建app命令Python manage.py startapp learn ,報錯:
No module named '_sqlite3'
解決:
#
# wget https://www.sqlite.org/snapshot/sqlite-snapshot-201708251543.tar.gz
# tar xfzv xxxx.tar.gz && make && make install
[email protected]
:/home/project/demosite# python manage.py runserver
Performing system checks...


System check identified no issues (0 silenced).


You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, 


contenttypes, sessions.
Run 'python manage.py migrate' to apply them.


September 02, 2017 - 10:51:11
Django version 1.11.4, using settings 'demosite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
執行#python manage.py migrate搞定!


問題3:在container中執行python manage.py runserver 127.0.0.1:8000
無法訪問,改為eth0的ip重新啟動django server。訪問時出現:
DisallowedHost at /
Invalid HTTP_HOST header: '210.41.225.59:8000'. You may need to add '210.41.225.59' to ALLOWED_HOSTS.
解決:
#vi demosite/settings.py
改為:ALLOWED_HOSTS = [ '*' ]
:wq
再web訪問:http://publicip:8000,回車出現:
It worked!
Congratulations on your first Django-powered page.