成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Deploy Django Project of local MySQL DB using Dock

Juven / 1285人閱讀

摘要:

Docker in Windows

Normally, those kinds of things will be much more troublesome when you want to run them in Windows compare to in Linux. However, Docker has made quite user-friendly for Windows. You just need to run the Docker installer and to enable below two things, then Docker will work like a charm.

Hyper-V

Virtualization in BIOS

Docker Files

Create this file with the name Dockerfile and put into your Django project root folder.

# Use an official Python runtime as a parent image
FROM python:2.7-slim

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app 
ADD . /app

# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt

# Make port 80 available to the world outside this container
EXPOSE 80

# Define environment variable
ENV NAME MySite

# Run manage.py when the container launches
CMD ["python", "manage.py", "runserver", "0.0.0.0:80"]

You can define any required modules in requirements.txt, and you don’t need Python or anything in requirements.txt on your system, nor will building or running this image install them on your system.

mysqlclient
Build it
docker build -t mysite .
Run the app, mapping your machine’s port 8000 to the container’s EXPOSED port 80 using -p:
docker run -p 8000:80 mysite
Docker-Compose (To be completed)

Create a file called docker-compose.yml in your project directory and paste the following:

version: "3"

services:
  mariadb:
    image: mariadb
    environment:
       - MYSQL_ROOT_PASSWORD=password
       - MYSQL_DATABASE=docker
       - MYSQL_USER=user
       - MYSQL_PASSWORD=password
  web:
    build: .
    command: python manage.py runserver 0:80
    volumes:
      - .:/app
    ports:
      - "8000:80"
    depends_on:
      - mariadb
Docker Useful Commands

List dangling images:

docker images -f dangling=true

Remove dangling images:

docker rmi -f $(docker images -f dangling=true -q)

Running an empty container:

docker run -it mysite /bin/bash

Remove a container:

docker rm -f 

Remove all stopped containers

docker rm $(docker ps -a -q)
Important for Windows Users and Using MySQL

You may use either docker or docker-compose to bring up your Django application, however, when in Windows and if you are using MySQL as DB, there will be an error "No modeul named MySQLdb" and when you want to install mysqlclient or libmysqlclient-dev, there will be another error of mysql_config() not found. So in the end, I need to install the packages manually.

Run the image as container and then get into the container

docker run -p 8000:8000 mysite
docker exec -i -t  /bin/bash

Run apt-get update in order to get all the packages

apt-get update

install mysql-server for mysql_config()

apt-get install mysql-server

install libmysqlclient-dev and gcc in order to install mysqlclient for MySQLdb

apt-get install libmysqlclient-dev
apt-get install gcc
pip install mysqlclient

If you need to import pycurl then you need to install the prerequisite packages

apt-get install libcurl4-gnutls-dev librtmp-dev
pip install pycurl

Finally, You can run the application and access it in your browser!

python manager.py runserver 0.0.0.0:8000

You could also save the changes to an image.

docker commit  :

文章版權歸作者所有,未經(jīng)允許請勿轉載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉載請注明本文地址:http://systransis.cn/yun/38696.html

相關文章

  • Deploy Django Project of local MySQL DB using Dock

    摘要: Docker in Windows Normally, those kinds of things will be much more troublesome when you want to run them in Windows compare to in Linux. However, Docker has made quite user-friendly for Window...

    Keagan 評論0 收藏0
  • Backup Database and Other Attachments in ROR

    摘要:定時任務命令詳解 Related Resources rsync:http://rsync.samba.org/ Crontab:http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5 Linux Crontab 定時任務 命令詳解:http://blog.csdn.net/tianlesoftware/article/details...

    WrBug 評論0 收藏0
  • python第三方庫之Django學習筆記二

    摘要:上一節(jié)項目框架已經(jīng)搭建完畢,現(xiàn)在開始連接數(shù)據(jù)庫,創(chuàng)建數(shù)據(jù)庫設置默認安裝了數(shù)據(jù)庫打開文件數(shù)據(jù)庫引擎數(shù)據(jù)庫的名字小貼士如果你選擇,數(shù)據(jù)庫是以文件的形式生成,要設置成絕對路徑創(chuàng)建表結構創(chuàng)建模型激活模型執(zhí)行命令執(zhí)行成功后目錄結構如下圖 上一節(jié)項目框架已經(jīng)搭建完畢,現(xiàn)在開始連接數(shù)據(jù)庫,創(chuàng)建model 1、數(shù)據(jù)庫設置python默認安裝了sqlite數(shù)據(jù)庫 打開文件:dayang/settings...

    Java3y 評論0 收藏0

發(fā)表評論

0條評論

Juven

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<