Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure the python development environment for docker

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to configure the python development environment with docker". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to configure the python development environment with docker".

Steps:

1. Install docker (not described in detail here)

# 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)

# 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

# View current container sudo docker ps-a # launch container docker start webdemo# into container docker attach webdemo, thank you for reading. The above is the content of "how to configure python development environment for docker". After the study of this article, I believe you have a deeper understanding of how to configure python development environment for docker, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report