1

I'm running a docker container and inside this container, I'm saving an image to the workdir of the container. I want to plot this image on a website with javascript. Inside the container, is a flask service running.

Saving the plot to the workdir of the docker container:

plt.savefig('/app/TrainingAccLoss.png')

my 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"]

Try to plot the image:

var img = document.createElement("img");
img.src = "/app/TrainingAccLoss.png";
document.body.appendChild(img);

When I'm trying to plot the image, I got an 404 Error.

GET http://localhost:4000/app/TrainingAccLoss.png 404 (NOT FOUND).

I don't know if there is a possibility to access a file that is inside the workdir.

Pritesh
  • 1,066
  • 3
  • 15
  • 35
li-la-lama
  • 23
  • 4

1 Answers1

0
var img = document.createElement("img");
    img.src = window.origin + "/TrainingAccLoss.png";

document.body.appendChild(img);

If your app is serving the app folder, this should work.

Berto
  • 42
  • 4
  • Unfortunately that didn't work, but I'm also not sure what you mean by "If your app is serving the app folder". – li-la-lama Aug 20 '19 at 12:14
  • I mean your code is using DOM manipulation and running on browser so I assume you are serving the above code as static files on the app folder, using your python server. May the image file is not being serve so is not accessible via http request. Maybe you can run your docker and, on your browser just check if the image is being serve, just try: http://localhost/TrainingAccLoss.png or http://localhost/app/TrainingAccLoss.png – Berto Aug 23 '19 at 08:16