青岛网站设计皆挺青岛山西建设工程执业注册中心网站
青岛网站设计皆挺青岛,山西建设工程执业注册中心网站,信用体系网站建设一体化建设,设计公司设计费报价单官网#xff1a;https://docs.docker.com/engine/reference/commandline/init/
简介 docker init是一个命令行实用程序#xff0c;可帮助初始化项目中的 Docker 资源。.dockerignore它根据项目的要求创建 Dockerfile、Compose 文件。这简化了为项目配置 Docker 的过程#…官网https://docs.docker.com/engine/reference/commandline/init/
简介 docker init是一个命令行实用程序可帮助初始化项目中的 Docker 资源。.dockerignore它根据项目的要求创建 Dockerfile、Compose 文件。这简化了为项目配置 Docker 的过程节省时间并降低复杂性。 最新版本docker init支持 Go、Python、Node.js、Rust、ASP.NET、PHP 和 Java 如何使用 1. 创建一个flask应用
mkdir flaskcd flasktouch app.py requirements.txt
# app.py
from flask import Flaskapp Flask(__name__)app.route(/)
def hello_docker():return h1 hello world /h1if __name__ __main__:app.run(debugTrue, host0.0.0.0)# requirements.txt
Flask
2. 生成Dockerfile docker-compose.yaml
docker init将扫描您的项目并要求您确认并选择最适合您的应用程序的模板。选择模板后docker init系统会要求您提供一些特定于项目的信息并自动为您的项目生成必要的 Docker 资源。docker init 选择应用程序平台对于我们正在使用的示例python.它将为您的项目建议值例如Python版本port、entrypoint命令 3. 查看生成的Dockerfile
# syntaxdocker/dockerfile:1# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/ARG PYTHON_VERSION3.11.7
FROM python:${PYTHON_VERSION}-slim as base# Prevents Python from writing pyc files.
ENV PYTHONDONTWRITEBYTECODE1# Keeps Python from buffering stdout and stderr to avoid situations where
# the application crashes without emitting any logs due to buffering.
ENV PYTHONUNBUFFERED1WORKDIR /app# Create a non-privileged user that the app will run under.
# See https://docs.docker.com/go/dockerfile-user-best-practices/
ARG UID10001
RUN adduser \--disabled-password \--gecos \--home /nonexistent \--shell /sbin/nologin \--no-create-home \--uid ${UID} \appuser# Download dependencies as a separate step to take advantage of Dockers caching.
# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.
# Leverage a bind mount to requirements.txt to avoid having to copy them into
# into this layer.
RUN --mounttypecache,target/root/.cache/pip \--mounttypebind,sourcerequirements.txt,targetrequirements.txt \python -m pip install -r requirements.txt# Switch to the non-privileged user to run the application.
USER appuser# Copy the source code into the container.
COPY . .# Expose the port that the application listens on.
EXPOSE 5000# Run the application.
CMD gunicorn app:app --bind0.0.0.0:5000
4. 查看生成的docker-compose.yaml文件 它编写了 docker-compose 配置来运行应用程序。由于我们的应用程序不包含与数据库的任何连接因此它注释掉了数据库容器可能需要的代码。 如果您想在 Flask 应用程序中使用数据库请从 docker-compose 文件中取消注释 db 服务配置创建一个包含机密的本地文件然后运行该应用程序。它还生成了 .dockerignore文件。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/89546.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!