使用 Docker 设置 Streamlit url

问题描述 投票:0回答:1

单独运行 Streamlit 应用程序时,我可以毫无问题地设置应用程序的 url(在本地)。

例如运行一个简单的文件

Test.py
,如下所示:

import streamlit as st

# set the app's title
st.title("Very simple app")

使用

streamlit run Test.py --server.port=8501 --server.address=0.0.0.0 --server.baseUrlPath=/Testweb/
我可以转到
http://0.0.0.0:8501/Testweb/
,这是我设置的正确网址。

但是使用 Docker 时,我无法访问正确的 url。

使用以下文件(与之前的

Test.py
一起,全部处于同一级别):

requirements.txt

streamlit==1.30.0

Dockerfile

# Use the official Python base image
FROM python:3.10.3

# Set the working directory inside the container
WORKDIR /app

# Copy the requirements.txt file and install the dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt

# Copy the app code into the container
COPY . .

# Set the command to run the app
CMD ["sh", "-c", "streamlit run Test.py --server.port=8501 --server.address=0.0.0.0 --server.baseUrlPath=/Testweb/"]

使用命令: 形象塑造:

docker build -t test-streamlit .
发射容器:
docker run -d --name test-streamlit-container test-streamlit

它不适用于正确的网址。相反,它部分地适用于“随机”网址,例如

http://172.17.0.2:8501/Testweb/

所以这就像端口和baseUrlPath正确地通过Docker传递,但不是服务器地址。

我也尝试添加一个

config.toml
,但又是服务器地址没有正确传递。

我做错了什么?它只是在完整的本地设置中使用 docker 运行一个简单的 Streamlit 应用程序。

谢谢!

python docker streamlit
1个回答
0
投票

您的应用程序设置完美无缺。您只需与主机共享容器端口即可。

构建图像:

docker build -t test-streamlit

运行图像:

docker run -p 8501:8501 test-streamlit

让您从主机访问应用程序的重要组件是

-p 8501:8501
,它有效地创建从主机上的端口 8501 到容器上的端口 8501 的链接。

您应该能够在主机浏览器上访问 http://127.0.0.1:8501/Testweb/ 以查看测试应用程序。

© www.soinside.com 2019 - 2024. All rights reserved.