I've been looking through the documentation and some tutorials but I cannot seem to find anything current on how to create a volume using the docker.py
library. Nothing I've found appears to be current as the create_host_config()
method appears to be non-existent. Any help in solving this issue or a push in the right direction would be greatly appreciated. Thanks to all of you.
I've searched the documentation on: https://docker-py.readthedocs.io/en/stable/ https://github.com/docker/docker-py
I tried using this old stack overflow example: How to bind volumes in docker-py?
I've also tried the client.volumes.create()
method.
I'm trying to write a class to make docker a bit easier for most people to deal with in python.
import docker
VOLUMES = ['/home/$USER', '/home/$USER/Desktop']
def mount(volumes):
mount_points = []
docker_client = docker.from_env()
volume_bindings = _create_volume_bindings(volumes)
host_config = docker_client.create_host_config(binds=volume_bindings)
def _create_volume_bindings(volumes):
volume_bindings = {}
for path in range(len(volumes)):
volume_bindings[volumes[path]] = {'bind': 'mnt' + str(path + 1),
'mode': 'rw'}
return volume_bindings