【发布时间】:2019-08-20 07:18:27
【问题描述】:
我正在运行一个 docker 容器,在这个容器内,我将一个图像保存到容器的工作目录中。我想用 javascript 在网站上绘制这张图片。在容器内部,正在运行一个烧瓶服务。
将绘图保存到 docker 容器的工作目录中:
plt.savefig('/app/TrainingAccLoss.png')
我的 Dockerfile:
# Use an official Python runtime as a parent image
FROM python:3.5
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "app.py"]
尝试绘制图像:
var img = document.createElement("img");
img.src = "/app/TrainingAccLoss.png";
document.body.appendChild(img);
当我尝试绘制图像时,出现 404 错误。
获取http://localhost:4000/app/TrainingAccLoss.png 404(未找到)。
我不知道是否有可能访问工作目录中的文件。
【问题讨论】:
-
该页面/浏览器是否也在 docker 容器中运行?
-
是的,网页也在docker容器中运行
-
确保您在 Flask 中指定了正确的静态文件夹。 stackoverflow.com/questions/20646822/…
标签: javascript python docker flask