Hello,
I'd like to know if this is possible to mount a nfs volume with docker-py since I didn't find any example that looks like my use case.
Here is the command that i'd like to execute :
docker service create --name pgtest--mount type=volume,target=/var/lib/postgresql/data,volume-opt=device=:/docker/pgtest,volume-opt=o=addr=10.x.x.x,volume-opt=type=nfs4 -p 5432 medzila/postgres
Thanks a lot for your support !
Untested, but something like this should work:
from docker import APIClient
from docker.types import Mount, ContainerSpec, TaskTemplate, DriverConfig
cli = APIClient()
driver_cfg = DriverConfig('nfs4', options={
'o': 'addr=10.x.x.x',
'device': ':/docker/pgtest'
})
m = Mount(type='volume', target='/var/lib/postgresql/data', driver_config=driver_cfg)
c_spec = ContainerSpec('medzilla/postgres', mounts=[m])
task_tmpl = TaskTemplate(c_spec)
cli.create_service(task_tmpl, name='pgtest')
Hello shin-
Thanks a lot. Just a little correction for others that have the same question:
from docker import APIClient
from docker.types import Mount, ContainerSpec, TaskTemplate, DriverConfig
cli = APIClient()
driver_cfg = DriverConfig(name=None, options={
'o': 'addr=10.x.x.x',
'device': ':/docker/pgtest'
'type': 'nfs4'
})
m = Mount(type='volume', target='/var/lib/postgresql/data', driver_config=driver_cfg, source=None)
c_spec = ContainerSpec('medzilla/postgres', mounts=[m])
task_tmpl = TaskTemplate(c_spec)
cli.create_service(task_tmpl, name='pgtest')
Kind regards,
Medzila.
Most helpful comment
Untested, but something like this should work: