Docker bind and volume mount

ambharesh venkatraman 61 Reputation points
2021-04-14T14:51:49.267+00:00

Hi,
I am trying to store a csv file inside a docker container and use binds to store it locally. The problem I'm facing is if i use just the file name to write to csv it is getting saved in /app directory. If I use any other path say /mydata/output.csv it's not getting stored.

If I use mount to store the file in local directory the container is failing with message "Error ./main.py is not a file or directory".

local_file_name="output.csv"
local_path = "/mydata/output"
os.mkdir(local_path)
upload_file_path = os.path.join(local_path, local_file_name)

with open(upload_file_path, 'a') as csvfile:
    print("opened csv file")
    csvwriter = csv.writer(csvfile)                   
    csvwriter.writerow(metalist)

Deployment manifest

"HostConfig": {
                    "Binds": [
                        "/opt/localstorage/output:/app"
                    ]
                }
Azure IoT Edge
Azure IoT Edge
An Azure service that is used to deploy cloud workloads to run on internet of things (IoT) edge devices via standard containers.
534 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,115 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sander van de Velde 28,311 Reputation points MVP
    2021-04-14T21:18:57.913+00:00

    Hello @ambharesh venkatraman ,

    To be able to read and write files located on the host file system, there are a couple of things to check:

    • the code which access the file system
    • The bindingof the container
    • Access to the file system folders

    You can investigate the folder access inside the module with

    sudo docker exec -i -t [the name of your azure iot edge module] /bin/bash

    Please check out this blog post where a comparable situation is investigated.

    2 people found this answer helpful.
    0 comments No comments