Today, I installed the Django development environment on my Centos6.5 machine and reported the following error when I installed the application using "django-admin.py startproject MyApp"
$ django-admin.py startproject MyApp
traceback (most recent call last):
File "/home/jhadmin/myenv/bin/ django-admin.py ", line 2, in <module>
django.core import Management
File"/home/jhadmin/myenv/lib/ python2.6/site-packages/django/__init__.py ", line 1, in <module>
django.utils.version import get_ Version
File "/home/jhadmin/myenv/lib/python2.6/site-packages/django/utils/version.py", line 7, in <module > from
django.utils.lru_cache import lru_cache
File "/home/jhadmin/myenv/lib/python2.6/site-packages/ django/utils/lru_cache.py ", line
fasttypes = {int, str, frozenset, type (None)},
^
syntaxerror: Invalid syntax
Check to see that the Python version of my machine is too old, CentOS6.5 Python is 2.6.6, and the latest Django (1.8.4) requirement for Python is 2.7.x, and I was thinking about upgrading my machine's Python, Also afraid of other applications have an impact, is worried about it, suddenly think can use Docker to solve my problems. Here's how I use Docker to build the Django development environment.
First create a directory to store the Docker configuration file, here I call django_env.
Create a Dockerfile file in the Django_env directory with the following file contents
From Centos:centos7
maintainer fanbin Kong "kongxx@hotmail.com"
RUN rpm-ivh http://dl.fedoraproject.org/pub/ epel/7/x86_64/e/epel-release-7-5.noarch.rpm
run yum install-y openssh-server sudo supervisor Python-pip
Run Sed-i ' s/usepam yes/usepam no/g '/etc/ssh/sshd_config
run echo ' Root:letmein ' | chpasswd
run SSH-KEYGEN-T dsa-f /etc/ssh/ssh_host_dsa_key
Run ssh-keygen-t rsa-f/etc/ssh/ssh_host_rsa_key
run mkdir/var/run/sshd
run Pip install Django
RUN mkdir-p/var/log/supervisor
COPY supervisord.conf/etc/supervisord.conf
expose
CMD ["/usr/bin/supervisord"]
Considering that there will be more than one service in the Docker, the supervisor is used to create a supervisord.conf file that reads
[Supervisord]
Nodaemon=true
[program:sshd]
command=/usr/sbin/sshd-d
Run the following command in the Django_env directory to generate a container mirror
Copy Code code as follows:
sudo docker build-t django_env.
To build a container from a container image
Copy Code code as follows:
sudo docker run-v/home/kongxx/mywork:/data--name=test-d-P django_env
"-v/home/kongxx/mywork:/data" is used here to share code in the host machine and container
After the container is generated, you can use the sudo docker inspect test | grep ipaddress command to view the IP address of the container. And then use SSH to log in to the container.
Copy Code code as follows:
After logging into the container, we can run the Django command to create and launch the application, as follows
Cd/data
django-admin.py startproject myapp
cd myapp
python manage.py runserver
At this point, you can see the service already running in the browser by accessing the http://:8000.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.