宫颈息肉是什么原因引起的| pg是什么激素| scr医学上是什么意思| 刷题是什么意思| 法盲是什么意思| 鹰和隼有什么区别| 沐雨栉风是什么生肖| 装修都包括什么| 玫瑰花泡水喝有什么功效| 婴儿老打嗝是什么原因| 全身无力是什么原因| 焦虑吃什么药| 风湿挂什么科| 男人梦到掉牙什么预兆| 头皮痒用什么药最有效| 圣经是什么| 黑洞是什么意思| 合寿木是什么意思| 牛腩烧什么好吃| 六十岁叫什么之年| 老是嗝气是什么原因| 为什么经常长口腔溃疡| 1973属什么生肖| 月牙代表什么意思| 田七配什么煲汤最好| 玉谷叶是什么植物| 对戒是什么意思| 流鼻血是什么病的前兆| 00属什么| 打狗看主人打虎看什么答案| 正装是什么样的衣服| barbie是什么意思| 背靠背协议是什么意思| 开封有什么好玩的地方| 突然尿频是什么原因| 黑豆腐是什么做的| 腺肌症是什么病| 什么茶不能喝| 酉时右眼跳是什么预兆| 为什么刚吃完饭不能洗澡| 麦霸什么意思| 光屏是什么| 落花生的落是什么意思| 水土不服是什么意思| 吃喝拉撒是什么意思| 丁克是什么意思| 小厨宝是什么东西| 梦到和妈妈吵架是什么意思| 为什么头出汗特别多| 物质是由什么组成的| 瘦的人吃什么才能变胖| 右脚浮肿预示着什么| 耳石症吃什么药| 烟酸是什么| 汗疱疹涂什么药| 禀赋是什么意思| 什么叫宿根太阳花| 体重用什么单位| 米醋是什么| y代表什么意思| 牛肉跟什么炒好吃| 是什么有什么| 交杯酒是什么意思| 脚背有痣代表什么| 窈窕淑女是什么生肖| 卤水点豆腐是什么意思| 溺水是什么感觉| 真太阳时是什么意思| 海尔洗衣机e3是什么故障| 为什么会有盆腔炎| 老是流鼻血是什么原因| 左手发麻是什么原因| 仔字五行属什么| hj是什么意思| 吃什么降三高最好| 梦见吐痰是什么意思| 敏字五行属什么| 虹吸是什么意思| 吃完油炸的东西后吃什么化解| 女孩子喜欢什么礼物| 皮炎用什么药| ns是什么单位| 鲍鱼吃什么| hbeab阳性是什么意思| 六合什么意思| 痿证是什么病| 前列腺吃什么食物调理| 贴黄瓜片对皮肤有什么好处| 什么是碱中毒| 11月18号是什么星座的| 玄凤鹦鹉吃什么| 气血不足吃什么食物好| 手指甲空了是什么原因| 大创是什么| 酒精胶是粘什么的| 尚可什么意思| 双喜临门的临是什么意思| 什么店可以买到老鼠药| 跨性别是什么意思| 金青什么字| 兆以上的计数单位是什么| 做梦梦到水是什么征兆| 闹乌龙是什么意思| 肉字五行属什么| 心率快吃什么药效果好| 国印是什么意思| 鱼刺卡喉咙去医院挂什么科| 喝酒前喝什么不容易醉又不伤胃| 为什么会晕3d| 鼻子毛白了是什么原因| 校草是什么意思| 拔牙后吃什么药| 水准仪是测量什么的| 吃土豆有什么好处和坏处| 睡眠浅是什么原因| 王玉是什么字| 拖鞋什么材质的好| 月经期间能吃什么水果| 天蝎和什么星座最配对| 莫须有是什么意思| 牛肉炒什么菜好吃| 不是你撞的为什么要扶| 头晕是什么原因| 胎盘1级什么意思| 6月25日是世界什么日| 黄花胶是什么鱼的胶| 梦见死去的朋友是什么意思| NT是检查什么| 腰上长痘痘是什么原因| 拉屎臭是什么原因| 火奥念什么| 青春痘长什么样| 日柱代表什么| 三伏天什么意思| 绿茶有什么功效| 眉毛里有痣代表什么| 龟头敏感用什么药| 老公的爸爸称谓是什么| 疱疹是什么症状| 北海龙王叫什么| 1932年属什么生肖| 朝拜的意思是什么| 特勤是干什么的| 膳食纤维有什么作用| 精分是什么| 凉皮是什么做的| 宋美龄为什么没有孩子| 肾结石忌口什么| 海苔是什么做的| 海棠依旧什么意思| 为什么会起湿疹| 噤口痢是什么意思| 钙片是什么意思| 人生苦短什么意思| ihc是什么意思| 青苹果什么时候成熟| 家里消毒杀菌用什么好| 心率130左右意味着什么| 荔枝什么人不能吃| 热敷肚子有什么好处| 先下手为强是什么意思| 舌头麻是什么病的前兆| 4.5是什么星座| 什么原因导致性功能减退| 缺营养吃什么补身体最好| 减肥期间可以吃什么水果| 养寇自重什么意思| affairs是什么意思| 大虾不能和什么一起吃| suki是什么意思| 腹泻吃什么药最好| 大利月小利月什么意思| 状元是什么官| 梦见自己牙齿掉了是什么意思| 正比和反比是什么意思| 黄褐斑是什么样的图片| 小孩肠胃感冒吃什么药比较好| 逍遥丸治什么| 炎黄子孙是什么生肖| 羊肉与什么食物相克| 胃不消化吃什么药好| 沸去掉三点水念什么| 脚脖子疼是什么原因| 一日三餐是什么生肖| 什么时候怀孕几率高| 什么食物可以降血糖| 五香粉是什么| 邹去掉耳朵旁读什么| 冰室是什么意思| 长期服用丙戊酸钠有什么副作用| 相什么无什么| 尿潴留是什么意思| qn医学上是什么意思| 梅州有什么大学| 梦见很多蜘蛛是什么意思| crab是什么意思| 三叉神经挂什么科| 党什么时候成立| 骨质疏松打什么针| 什么专业就业前景好| 口真念什么| pra是什么意思| 七点半是什么时辰| 脚心发麻是什么原因引起的| 耳朵听不清楚是什么原因| 梦到两条蛇预示着什么| 什么是溶血性贫血| 什么是激素类药物| 3月23日是什么星座| 幡是什么意思| 人属于什么界门纲目科属种| 西周王陵为什么找不到| 十点多是什么时辰| 10月26日什么星座| 咽炎是什么症状| 反文旁和什么有关| 日柱华盖是什么意思| 7月23日是什么日子| 8.11是什么星座| 未来是什么意思| 月经前腰疼是什么原因| 阴唇为什么会长痘痘| 四个一是什么| 血窦是什么意思| 鸡蛋饼用什么面粉| 苹果吃了有什么好处| 尿频尿急吃什么药| 83岁属什么生肖| qn医学上是什么意思| 脾胃是什么意思| 黄酒有什么功效与作用| 胃痛吃什么| 梦见抓鱼是什么预兆| 什么家欢乐| 12月31号什么星座| 直立倾斜试验阳性是什么病| 转氨酶高是什么原因引起的| 普洱茶是什么茶类| 鳄鱼吃什么食物| 乳酸是什么东西| 身体发抖是什么病| 金牛男最烦什么女孩| 早上口干舌燥是什么原因| 左行气右行血什么意思| 五月初九是什么星座| 21岁属什么生肖| 什么的心情| 芙蓉是什么意思| 品检是做什么的| 2月30日是什么星座| 子宫内膜增厚是什么原因| 臻字五行属什么的| 心率用什么字母表示| 男性补肾壮阳吃什么药效果比较好| 支气管炎是什么| 效劳是什么意思| 胃气胀是什么原因怎么解决| 冬至有什么禁忌| 皮肤病用什么药膏好| 吃紧急避孕药有什么副作用| 老年痴呆症是什么原因引起的| 叶绿素主要吸收什么光| cba什么意思| 犹太人说什么语言| 百度

Try to extend agent mode in VS Code!

三星s8屏幕泛红怎么办 三星s8屏幕泛红解决方法

百度 《办法》加强资本真实性监管。

In this tutorial, you will learn how to:

  • Create a Dockerfile file describing a simple Python container.
  • Build, run, and verify the functionality of a Django, Flask, or General Python app.
  • Debug the app running in a container.

Prerequisites

  • Install Docker on your machine and add it to the system path.

  • On Linux, you should also enable Docker CLI for the non-root user account that will be used to run VS Code.

  • The Container Tools extension. To install the extension, open the Extensions view (??X (Windows, Linux Ctrl+Shift+X)), search for container tools to filter results and select the Container Tools extension authored by Microsoft.

    Select Container Tools extension

Create a Python project

If you don't have a Python project already, follow the tutorial Getting started with Python.

Note: If you want to containerize a complete Django or Flask web app, you can start with one of the following samples:

Note: For this tutorial, be sure to use the tutorial branch of the sample repos.

After verifying your app runs properly, you can now containerize your application.

Add Docker files to the project

  1. Open the project folder in VS Code.

  2. Open the Command Palette (??P (Windows, Linux Ctrl+Shift+P)) and choose Containers: Add Docker Files to Workspace...:

    Add Dockerfile to a Python project

  3. When prompted for the app type, select Python: Django, Python: Flask, or Python: General as the app type. For this tutorial, we'll focus on the Python: General case, but will also include notes for Django and Flask.

  4. Enter the relative path to the app's entry point. This excludes the workspace folder you start from. If you created a python app with hello.py according to the Getting Started with Python tutorial, choose that.

    Django: Choose manage.py (root folder) or subfolder_name/manage.py. See the official Django documentation.

    Flask: Choose the path to where you create your Flask instance. See the official Flask documentation.

    Tip: You may also enter the path to a folder name as long as this folder includes a __main__.py file.

  5. Select the port number. We recommend selecting port 1024 or above to mitigate security concerns from running as a root user. Any unused will port, but Django and Flask use standard default ports.

    Django: The default port 8000.

    Flask: The default port is 5000.

  6. When prompted to include Docker Compose, select No if you do not want a Docker Compose file. If you select Yes, you will need to verify the path to your wsgi.py file in the Dockerfile to run the Compose Up command successfully. Compose is typically used when running multiple containers at once.

  7. With all this information, the Container Tools extension creates the following files:

    • A Dockerfile. To learn more about IntelliSense in this file, refer to the overview.

    • A .dockerignore file to reduce the image size by excluding files and folders that aren't needed such as .git, .vscode, and __pycache__.

    • If you're using Docker Compose, a docker-compose.yml and docker-compose.debug.yml file.

    • If one does not already exist, a requirements.txt file for capturing all app dependencies.

    Important Note: To use our setup, the Python framework (Django/Flask) and Gunicorn must be included in the requirements.txt file. If the virtual environment/host machine already has these prerequisites installed and is supposed to be identical to the container environment, ensure app dependencies are ported over by running pip freeze > requirements.txt in the terminal. This will overwrite your current requirements.txt file.

(Optional) Add an environment variable to the image

This step is not required, but it is included to help you understand how to add environment variables that need to be set in the container's environment.

The Container Tools extension helps you author Dockerfiles by using IntelliSense to provide auto-completions and contextual help. To see this feature in action:

  1. Open the Dockerfile.

  2. Underneath the EXPOSE statement, type ?Space (Windows, Linux Ctrl+Space) to trigger IntelliSense and scroll to ENV.

    Adding environment variable to Dockerfile

  3. Press Tab or Enter to complete the statement, then set the key to the name of the variable, and set the value.

For more information about setting and using environment variables in the Dockerfile, see the ENV instruction and Environment replacement section in the Docker documentation.

Gunicorn modifications for Django and Flask apps

To give Python web developers a great starting point, we chose to use Gunicorn as the default web server. Since it is referenced in the default Dockerfile, it is included as a dependency in the requirements.txt file. If you don't see it in requirements.txt, run pip install gunicorn and then run pip freeze > requirements.txt to regenerate the requirements.txt file.

  • Django: To use Gunicorn, it must bind to an application callable (what the application server uses to communicate with your code) as an entry point. This callable is declared in the wsgi.py file of a Django application. To accomplish this binding, the final line in the Dockerfile says:

    CMD ["gunicorn", "--bind", "0.0.0.0:8000", "{workspace_folder_name}.wsgi"]
    

    If your project does not follow Django's default project structure (that is, a workspace folder and a wsgi.py file >within a subfolder named the same as the workspace) you must overwrite the Gunicorn entry point in the Dockerfile to locate the correct wsgi.py file.

    If your wsgi.py file is in the root folder, the final argument in the command above will be "wsgi". Within subfolders, the argument would be "subfolder1_name.subfolder2_name.wsgi".

  • Flask: To use Gunicorn, it must bind to an application callable (what the application server uses to communicate with your code) as an entry point. This callable corresponds with the file location and variable name of your created Flask instance. According to official Flask Documentation, users generally create a Flask instance in the main module or in the __init__.py file of their package in this manner:

    from flask import Flask
    app = Flask(__name__) # Flask instance named app
    

    To accomplish this binding, the final line in the Dockerfile says:

    CMD ["gunicorn", "--bind", "0.0.0.0:5000", "{subfolder}.{module_file}:app"]
    

    During the Containers: Add Docker Files to Workspace... command, you configure the path to the Flask instance, however, the Container Tools extension assumes your Flask instance variable is named app. If this is not the case, you must change the variable name in the Dockerfile.

    If your main module was in the root folder as a file named main.py and had a Flask instance variable was named myapp, the final argument in the command above will be "main:myapp". Within subfolders, the argument would be "subfolder1_name.subfolder2_name.main:myapp".

Build, run, and debug the container

The Containers: Add Docker Files to Workspace... command automatically creates a Docker launch configuration to build and run your container in debug mode. To debug your Python app container:

  1. Navigate to the file that contains your app's startup code, and set a breakpoint.

  2. Navigate to Run and Debug and select Containers: Python - General, Containers: Python - Django, or Containers: Python - Flask, as appropriate.

    Selected container debug configuration

  3. Start debugging using the F5 key.

    • The container image builds.
    • The container runs.
    • The python debugger stops at the breakpoint.
  4. Step over this line once.

  5. When ready, press continue.

The Container Tools extension will launch your browser to a randomly mapped port:

Django website launches

Tip: To modify your Docker build settings, such as changing the image tag, navigate to .vscode -> tasks.json under the dockerBuild attribute in the docker-build task. Use IntelliSense within the file (?Space (Windows, Linux Ctrl+Space)) to display all other valid directives.

Use the Container Explorer

The Container Explorer provides an interactive experience to examine and manage container assets such as containers, images, and so on. To see an example:

  1. Navigate to the Container Explorer.

  2. In the Containers tab, right-click on your container and choose View Logs.

    Viewing the logs of a container

  3. The output will be displayed in the terminal.

Build the image in Azure

You can use the command Azure Container Registry: Build Image in Azure to build an image that you can then deploy to Azure App Service or Azure Container Apps.

  1. Install the Azure Resources extension. Open the Command Palette (??P (Windows, Linux Ctrl+Shift+P)) and search for the command Azure: Sign In. If you don't have an Azure account, you can sign up for a free trial.

  2. There are two ways to invoke the build in Azure command. You can right-click on the Dockerfile, and choose Build Image in Azure. You can also use the Command Palette (??P (Windows, Linux Ctrl+Shift+P)) and search for the command Azure Container Registry: Build Image in Azure.

    Invoke the command Build Image in Azure

  3. Choose the name and tag for the built image. You'll use this to identify it in the container registry.

    Choose the name and tag for the built image.

  4. Choose the Azure subscription you want to use.

  5. Choose an existing Azure Container Registry, or create a new one. When you create a new one, you're asked to provide the name, resource group, location, and an option for pricing, such as Basic, Standard, or Premium. You can read about the costs of these options at Pricing - Container Registry.

  6. Specify the base OS, Linux or Windows. This choice must be consistent with the Dockerfile.

    Choose the base OS for the built image

The process of building the image might take a few minutes. You can track progress in the terminal. If you encounter an error (Error: failed to download context.), try using the Refresh option on the container registry and then request another build. Before rebuilding, manually delete the old image.

Deploy to Azure App Service or Azure Container Apps

Once the container image is built, it should appear in the Container Registry with the tag you specified. Now that it's built, you can deploy it to Azure App Service or Azure Container Apps. The Azure App Service extension is recommended for deployments to Azure App Service, and the Azure Container Apps extension is required for deployments to Azure Container Apps. You can obtain both if you install the Azure Tools extension pack, which includes a package of tools for a wide range of Azure development scenarios.

  1. Right-click on the image tag and choose Deploy Image to Azure App Service or Deploy Image to Azure Container Apps.

    Deploy image to Azure App Service

  2. Provide the name of the web site. This must be a unique name, and for Django apps, it must also be listed as a valid host name in the ALLOWED_HOSTS list in the settings.py file.

  3. Provide a resource group, location, and App Service Plan. If you're just getting started, you can choose the free plan.

  4. The image is deployed; the process might take a few minutes. Once it's deployed, a notification appears with a button you can use to access the site. You can also use the site's address, {appname}.azurewebsites.net where {appname} is the name you gave when creating it. If it doesn't work at first, try again in a few minutes. It's not uncommon for the first few attempts to time out or return an error. It just means the App Service isn't ready yet to receive requests.

  5. Make a small change in the application code that's visible on one of the pages, and save the file.

  6. Use the Azure icon to open the Resources view, and expand the node for your subscription to find the App Service that you deployed in the previous step.

  7. Right-click on the App Service node and look at the available options. Choose Deploy to Web App, and then specify your app folder to deploy it.

    Deploy to Web App

    When warned that this will overwrite the previous deployment, choose Deploy to confirm.

    This might take a few minutes; you can monitor progress in the terminal window. When it finishes, a button with access to the site is given.

    Browse website button

    Use the button and verify that your change is reflected on the site.

Congratulations, you've used Python in VS Code to create an deploy a web site that's hosted in the cloud and live on the internet!

Free up resources

In the Azure portal, delete the Resource Group to free up all resources that you created during this exercise.

Next steps

You're done! Now that your container is ready, you may want to:

叫人挪车打什么电话 什么饺子馅好吃 扑朔迷离是什么意思 女生吃什么可以丰胸 除湿是什么意思
红糖荷包蛋有什么功效 眼睛红血丝是什么原因 脾大吃什么药能缩小 睡觉翻白眼是什么原因 世界上最长的蛇是什么
pu皮是什么材质 艾灸为什么不能天天灸 枸杞泡水喝有什么作用 毒龙钻是什么 影射是什么意思
吃什么防止脱发掉发 孩子发烧是什么原因引起的 五彩斑斓的意思是什么 感叹号像什么 生意盎然什么意思
吃什么补肾壮阳最快速hcv9jop5ns8r.cn ppi是什么wmyky.com 口幼读什么mmeoe.com 脖子上有结节挂什么科hcv9jop1ns5r.cn 黑苦荞茶适合什么人喝hcv8jop8ns6r.cn
孕妇什么时候做nthcv7jop4ns5r.cn 肾功能四项检查什么hcv8jop4ns7r.cn 微凉是什么意思hcv9jop3ns7r.cn 术前四项检查是什么hcv8jop2ns3r.cn 心衰做什么检查能确诊hcv9jop8ns1r.cn
白羊座男和什么星座最配hcv9jop0ns9r.cn 十月十日什么星座hcv7jop5ns5r.cn 脂肪肝什么东西不能吃youbangsi.com 内向是什么意思hcv9jop5ns2r.cn 低钠盐是什么意思hcv7jop4ns8r.cn
耳石症吃什么药最好hcv8jop3ns9r.cn 中年人手抖是什么原因hcv9jop3ns2r.cn 什么是cdhuizhijixie.com 什么是硬盘hanqikai.com 吃什么食物对肝好hcv9jop6ns9r.cn
百度