简体   繁体   中英

How to access volume mount with python script?

I have been trying to use something along these lines to access a file in a volume mount:

with open('./log/file.json', 'w+') as f:
    f.write(json.dumps(output, sort_keys=True, indent=4))

but it is not working. Are there any ideas? In my deployment file, I have this:

volumeMounts:
- mountPath: /logs
  name: wag-log

You've defined a volumeMount with the mountPath set to /logs , which would mount a volume into the /logs directory. In your Python code you're writing at the path ./log/file.json , which is not in /logs .

Try to write a log to the directory you mounted, for example:

with open('/logs/file.json', 'w+') as f:
    f.write(json.dumps(output, sort_keys=True, indent=4))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM