Mount of volume-subpath which is available in Docker version 26.0.0, build 2ae903e using Python SDK for docker

Hi ,

I found a docker volume option “volume-subpath” in the Docker version 26.0.0. This could be used to mount a sub-directory or a sub-path inside a host docker volume to a container without mounting the entire host volume.

But while using Python SDK for docker, I am not able to use this volume option. Only source and target options were seen for docker volume configuartion using Python.

Is there any way to tackle this issue? I need this feature as part of a project developement. Please provide me some solution to implement this concept using Python.

We are developing in Linux 6.2.0-39-generic Ubuntu 22.04.1 with Python 3.10.12

Thanks in advance,
Abijith V S
Product Developer

You should probably create an issue on Github.

1 Like

Do you mean Docker SDK for Python? The latest version was released in december, 2023. SubPath was introduced in the engine API v1.45

  • POST /containers/create now supports VolumeOptions.Subpath which allows a subpath of a named volume to be mounted.

The current default API version in the SDK is 1.44 and default engine version is 25.0.

The SDK supports specifying the API version

https://docker-py.readthedocs.io/en/stable/client.html?highlight=version#docker.client.from_env

Parameters:

  • version (str) – The version of the API to use. Set to auto to automatically detect the server’s version. Default: auto

You can try that, but I wouldn’t be surprised if it didn’t work as Docker 26.0.0 is two weeks old and I don’t know how fast they make the SDK compatible with the latest versions.

Thanks for the information. We will look into it