简体   繁体   English

如何为 strealit 应用程序创建 Dockerfile

[英]How to create a Dockerfile for strealit app

I am aiming to deploy a web-app written with Sreamlit,我的目标是部署一个用 Sreamlit 编写的网络应用程序,

文件结构

I can run this on my local machine by running streamlit run Home.py in my command line.我可以通过在命令行中运行 streamlit run Home.py 在本地机器上运行它。

However, I'm not sure how to create the docker file.但是,我不确定如何创建 docker 文件。

Any advice?有什么建议吗?

Try something like this.尝试这样的事情。

FROM python:3.7

# Expose port you want your app on
EXPOSE 8080

# Upgrade pip and install requirements
COPY requirements.txt requirements.txt
RUN pip install -U pip
RUN pip install -r requirements.txt

# Copy app code and set working directory
COPY . .
WORKDIR /app

# Run
ENTRYPOINT [“streamlit”, “run”, “Home.py”, “–server.port=8080”, “–server.address=0.0.0.0”]

This is a docker file that would work for you:这是一个适合您的 docker 文件:

FROM python:3.9
WORKDIR /app
COPY requirements.txt ./requirements.txt
RUN pip3 install -r requirements.txt
COPY . .
EXPOSE 8201
ENTRYPOINT ["streamlit", "run"]
CMD ["app/Home.py"]

This is a series of instructions and each instruction creates a layer.这是一系列指令,每条指令创建一个层。 The base image here is python:3.9 where you create a directory called /app , then copy and install everything in your requirements.txt .此处的基本映像是python:3.9 ,您可以在其中创建一个名为/app的目录,然后复制并安装您的requirements.txt中的所有内容。 Then copy your entire folder over and finally specify the command to run within the container.然后复制整个文件夹,最后指定要在容器中运行的命令。 When you run the container it will be exposed on port 8201 .当您运行容器时,它将在端口8201上公开。

Build and run the container with the following if you are going for a local set up.如果您要进行本地设置,请使用以下内容构建并运行容器。 Run the commands from within the directory your Dockerfile is.Dockerfile所在的目录中运行命令。

docker build -f Dockerfile -t app:latest .
docker run -p 8201:8201 app:latest

Now you will be able to access the container on your browser at http://localhost:8201/现在您将能够在浏览器上通过http://localhost:8201/访问容器

In order to Dockerise your app you need two files:为了对您的应用进行 Dockerise,您需要两个文件:

  1. Dockerfile : describes the image structure, Dockerfile : 描述镜像结构,
  2. docker-compose.yml : describes how to make a container from that image ( Dockerfile ) docker-compose.yml :描述如何从该图像( Dockerfile )创建一个容器

The answer of Javier Roger is providing a very minimal Dockerfile that seems to work: Javier Roger的答案是提供了一个非常小的 Dockerfile,它似乎可以工作:

FROM python:3.7

# Expose port you want your app on
EXPOSE 8080

# Upgrade pip and install requirements
COPY requirements.txt requirements.txt
RUN pip install -U pip
RUN pip install -r requirements.txt

# Copy app code and set working directory
COPY . .
WORKDIR /app

# Run
ENTRYPOINT [“streamlit”, “run”, “Home.py”, “–server.port=8080”, “–server.address=0.0.0.0”]

If you combine this answer with the following docker-compose then you have a nice container containing your app:如果您将此答案与以下 docker-compose 结合使用,那么您将拥有一个包含您的应用程序的漂亮容器:

services:
  streamlit:
    container_name: "The name you want to have your container"
    build:
      dockerfile: ./Dockerfile
      context: ./
    ports:
      - 'The port you want your app to have:8080'

Please note that both Dockerfile and docker-compose.yml should be placed in the root of your app.请注意, Dockerfiledocker-compose.yml都应该放在应用程序的根目录中。

To run the app just cd to the root dir and run:要运行应用程序,只需cd到根目录并运行:

docker compose up -d

if docker compose is not installed please use:如果未安装 docker compose,请使用:

 sudo apt-get update
 sudo apt-get install docker-compose-plugin

In case that you cannot install it so easily use this link如果您无法轻松安装它,请使用此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为 python 应用程序创建多级 dockerfile? - How to create a multistage dockerfile for a python app? 在 Flask 应用程序中为 dash 应用程序创建 dockerfile - Create the dockerfile for dash app within Flask app 创建一个 dockerfile 来运行 python 和 groovy 应用程序 - create a dockerfile to run python and groovy app Docker 在 Dockerfile 中创建卷并在其上编译应用程序 - Docker create volumes in Dockerfile and compile app on it 如何创建在Ubuntu容器中安装Python 3和nltk的Dockerfile? - How to create Dockerfile which installs Python 3 and nltk in a Ubuntu container? 如何使用 R + Anaconda3 + 非 root 用户创建 Dockerfile - How to create Dockerfile with R + Anaconda3 + non-root User 如何使用 scl enable 在 dockerfile 中运行 python3 应用程序 - How to use scl enable to run python3 app in dockerfile 无法在dockerfile中创建conda env - Cant create conda env in dockerfile 'exec: gunicorn: not found' 但在 requirements.txt 中,如何添加到 Google App Engine Dockerfile 配置的应用程序路径? - 'exec: gunicorn: not found' but is in requirements.txt, how to add to Google App Engine Dockerfile-configured app path? 如何制作 Dockerfile? - How to make a Dockerfile?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM