In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use docker to cooperate with the python development environment, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Because we need to rely on a large number of three-party library packages when developing a Python program, and python2 and 3 are incompatible with each other, we often need an isolated environment to avoid bug caused by version impact.
In traditional practice, most people may choose virtualenv for isolation, but it has many obvious disadvantages:
Unable to provide complete isolation
If you don't want to use it in a formal environment, it can make a difference.
With the increasing maturity and popularization of container technology, Docker has undoubtedly become the best solution to this problem.
This article will mainly introduce the cooperative development of docker and flask.
Steps:
1. Install Docker
# reference command sudo wget-qO- https://get.docker.com/ | sh
two。 Application directory structure
├── fanxiangce_docker ├── Dockerfile ├── Readme.md └─ fanxiangce └── app ├── manage.py └── requirements ├── common.txt
3. Write Dockerfile (for detailed command explanation, please refer to https://docs.docker.com/engine/reference/builder/#environment-replacement)
# Dockerfile to run a flask-based web application# Based on an centos:7 image # # Set the base image to use to centos FROM centos:7# Set the file maintainer MAINTAINER jasonwang Wjs7740@163.com# Set env varibles used in this Dockerfile (add a unique prefix Such as DOCKYARD) # Local directory with project source ENV DOCKYARD_SRC=fanxiangce# Directory in Container for all project files ENV DOCKYARD_SRCHOME=/opt # Directory in container for project source files ENV DOCKYARD_SRCPROJ=/opt/fanxiangce# Update the defualt application repository source list RUN yum-y install epel-release RUN yum-y install python-pip RUN yum clean all# Copy application source code to SRCDIR COPY $DOCKYARD_SRC $DOCKYARD_SRCPROJ# Create application subdirectories WORKDIR $DOCKYARD_SRCPROJ RUN mkdir log VOLUME ['$DOCKYARD_SRCPROJ/log/'] # Install Python dependencies RUN pip install-- upgrade pipRUN Pip install-r $DOCKYARD_SRCPROJ/requirements/common.txt# Port to expose EXPOSE 800 million Copy entrypoint script into the image WORKDIR $DOCKYARD_SRCPROJ
4. Build image
# sudo docker build-t jason/webdemo under the same level directory of Dockerfile.
Successfully is displayed after success, and mirror ID is returned, as shown in the figure:
5. View and start the mirror
Note that the port mapped here (host port: container port), and the container port should be the same as the port defined by the flask application
Sudo docker imagessudo docker run-it-- name webdemo-p 8000 name webdemo 8000 jason/webdemo / bin/bash
6. Start the flask application in the container
Python manage.py runserver-p 8000
The successful startup is as follows:
7. You can access the application by typing 127.0.0.1rig 8000 in the browser.
8. Follow up
If you need to enter again after the container is closed, you can use the following command
# check the current container sudo docker ps-a # launch container docker start webdemo# into container docker attach webdemo, thank you for reading this article carefully. I hope the article "how to use docker to cooperate with python development environment" shared by the editor will be helpful to everyone. At the same time, I hope you will support it and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Touch a good article from metalink Oracle 10g Segment shrink=Mandatory=Init.ora paramet
© 2024 shulou.com SLNews company. All rights reserved.