CentOS6.5 sets up the Django development environment
- 2020-05-17 05:42:40
- OfStack
Today, I installed the Django development environment on my Centos6.5 machine, and the following error was reported when I created 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>
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
After checking 1, I found that the version of python on my machine is too old, Python of CentOS6.5 is 2.6.6, while the latest version of django (1.8.4) requires Python version 2.7.x. I was thinking of upgrading Python of my machine for 1, but I was afraid that it would have an impact on other applications. Here are the steps I took to build the django development environment using Docker.
First, create a directory to hold the Docker configuration file, which I will call django_env.
Create an Dockerfile file in the django_env directory as follows
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 22
CMD ["/usr/bin/supervisord"]
Considering that multiple services will be launched in Docker later, supervisor is still used. Create an supervisord.conf file as follows
[supervisord]
nodaemon=true
[program:sshd]
command=/usr/sbin/sshd -D
Run the following command in the django_env directory to generate the container image
sudo docker build -t django_env .
Generate containers based on the container image
sudo docker run -v /home/kongxx/mywork:/data --name=test -d -P django_env
Here use "- v/home/kongxx/mywork: / data", the purpose is to can share code in the host machine and the container
Once the container is generated, the IP address of the container can be viewed using the command "sudo docker inspect test | grep IPAddress". Then use ssh to log into the container
ssh root@<container_ip>
After logging into the container, we can run the django command to create and launch the application, as shown below
cd /data
django-admin.py startproject myapp
cd myapp
python manage.py runserver 0.0.0.0:8000
At this point, visit http://:8000 in your browser to see that the service is up and running.