My first question is: What is a docker volume? Is it an instance of the code? So if I write to a file, the file is written to that volume's version of the file?
Here is my data structure:
static
---scripts
---styles
---templates
matrices
--- sampleMatrix.txt <- this is the file I'm trying desperately to write to
app.py
dockerfile
docker-compose.yml
App.py code:
try:
matrixFile= open(fileName, "w+")
matrixFile.write("text: \n") <- should print test:
print("wrote to: ",fileName, file=sys.stderr)
matrixFile.close()
matrixFile= open(fileName, "w+")
print("About to read: ",fileName, file=sys.stderr)
print(matrixFile.read(), file=sys.stderr) <- prints a newline and nothing else
print("Read from: ",fileName, file=sys.stderr)
matrixFile.close()
except:
print("cant open file", file=sys.stderr) <- never prints
With this, I know that flask is FINDING the file but seems not to be writing anything to it. Also no changes to the file locally
dockerfile:
FROM python:3.6.1-alpine
ADD . .
RUN pip install -r requirements.txt
RUN pip install requests
VOLUME [ "/matrices/" ]
CMD ["python","app.py"]
docker-compose.yml
version: '2'
services:
<containerName>:
build: .
ports:
- 82:80
container_name: <containerName>
volumes:
- ~<userName>/Desktop/<folderName>/matrices/:/matrices/
I thought possibly the path of the volume could be wrong but I can't tell how to check. If this was theoretically working correctly, would I see changes to the local file immediately?