摘要:
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 FilesCreate 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.
mysqlclientBuild 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 mysiteDocker-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: - mariadbDocker 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:
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/26952.html
摘要: 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...
摘要:定时任务命令详解 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...
摘要:上一节项目框架已经搭建完毕,现在开始连接数据库,创建数据库设置默认安装了数据库打开文件数据库引擎数据库的名字小贴士如果你选择,数据库是以文件的形式生成,要设置成绝对路径创建表结构创建模型激活模型执行命令执行成功后目录结构如下图 上一节项目框架已经搭建完毕,现在开始连接数据库,创建model 1、数据库设置python默认安装了sqlite数据库 打开文件:dayang/settings...
阅读 1876·2021-09-24 09:48
阅读 3219·2021-08-26 14:14
阅读 1674·2021-08-20 09:36
阅读 1460·2019-08-30 15:55
阅读 3627·2019-08-26 17:15
阅读 1425·2019-08-26 12:09
阅读 606·2019-08-26 11:59
阅读 3323·2019-08-26 11:57