How do I set the "mounts" option in the "create_host_config" to mount a Windows UNC path (or lettered path) network drive within the Docker SDK?

Published

Any and all help appreciated! I’m specifically trying to use the DockerRun flow configuration within a Prefect flow. The DockerRun flow config uses "create_host_config" of the python Docker SDK. If I mount a local path, the Docker Agent has no problem binding and reading/writing to the path. However, when I pass a network path, I get 1 of 2 errors depending on how I configure.

  1. First error says that I am not using valid characters and I must pass absolute path instead (complaining about I believe)
  2. Second error complains that I pass invalid argument when I try to pass in my username/password for accessing the Windows network path.

For example:

### THIS CODE ALLOWS ME TO BIND A LOCAL FILE PATH
from prefect.run_configs import DockerRun
import docker

with Flow("some_flow") as flow:
  # execute tasks

flow.storage = Docker(...)

flow.run_config = DockerRun(labels=['my-label']
                            ,host_config={'mounts':[docker.types.Mount(target='/public'
                                                                        ,source=r'//c/some/local/path'
                                                                        ,type='bind')
                                                ]
                                        }
                        )

### THIS CODE THROWS BAD CHARACTER ERROR 
flow.run_config = DockerRun(labels=['my-label']
                            ,host_config={'mounts':[docker.types.Mount(target='/public'
                                                    ,source=r'pathtowindowsnetworkshareddrive'
                                                                        ,type='bind')
                                                ]
### THIS CODE THROWS AN INVALID ARGUMENT ERROR
flow.run_config = DockerRun(labels=['my-label']
                                    ,host_config={'mounts':[
                                        docker.types.Mount(target='/public'
                                                            ,source='local'
                                                            ,type='volume'
                                                            ,driver_config=docker.types.DriverConfig(name='local'
                                                                                                    ,options={'type':'cifs'
                                                                                                            ,'device':r'pathtowindowsnetworkdrive'
                                                                                                            ,'credentials':'user=<username>,domain=<windows_domain>,password=<password>'
                                                                                                            }
                                                                                                    )  
                                                            )
                                                        ]
                                                }           
                            )

Source: Docker Questions

Published
Categorised as docker, prefect, sdk, windows Tagged , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq