CentOS6.5 sets the Django development environment, centos6.5django

Source: Internet
Author: User

CentOS6.5 sets the Django development environment, centos6.5django

Today I installed the Django Development Environment on my Centos6.5 machine and reported the following error when I used django-admin.py startproject myapp to create the application after installation

$ django-admin.py startproject myappTraceback (most recent call last): File "/home/jhadmin/myenv/bin/django-admin.py", line 2, in <module> from django.core import management File "/home/jhadmin/myenv/lib/python2.6/site-packages/django/__init__.py", line 1, in <module> from 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 28 fasttypes = {int, str, frozenset, type(None)},  ^SyntaxError: invalid syntax

Check that the python version on my machine is too old. The Python version of CentOS6.5 is 2.6.6, And the Python version required by django (1.8.4) is 2.7.x, I want to upgrade my machine's Python, and I am afraid it will affect other applications. I am worried. I suddenly thought I could use Docker to solve my problem. The following describes how to build a django development environment using Docker.

First, create a directory to store the Docker configuration file. Here I am called django_env.

Create a Dockerfile under the django_env directory. The file content is as follows:

FROM centos:centos7MAINTAINER Fanbin Kong "kongxx@hotmail.com"RUN rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpmRUN yum install -y openssh-server sudo supervisor python-pipRUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_configRUN echo "root:Letmein" | chpasswdRUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_keyRUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_keyRUN mkdir /var/run/sshdRUN pip install djangoRUN mkdir -p /var/log/supervisorCOPY supervisord.conf /etc/supervisord.conf EXPOSE 22 CMD ["/usr/bin/supervisord"]


Considering that multiple services will be started in Docker, the supervisor is used to create a supervisord. conf file. The content is as follows:

[supervisord]nodaemon=true[program:sshd]command=/usr/sbin/sshd -D

Run the following command in the django_env directory to generate a container Image

Copy codeThe Code is as follows: sudo docker build-t django_env.

Generate a container Based on the container Image

Copy codeThe Code is 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 the code in the host machine and container.

After the container is generated, run the "sudo docker inspect test | grep IPAddress" command to view the IP address of the container. Then use ssh to log on to the container

Copy codeThe Code is as follows: ssh root @ <container_ip>

After logging on to the container, we can run the django command to create and start the application, as shown below:

cd /datadjango-admin.py startproject myappcd myapppython manage.py runserver 0.0.0.0:8000

In this case, access http: //: 8000 in the browser to see that the service is running.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.