#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
root@cdc300fb3bc4:/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.
#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
root@cdc300fb3bc4:/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.