2

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
Vedprakash Wagh
  • 3,595
  • 3
  • 12
  • 33

1 Answers1

0

Perhaps you want to use the Low-level API client?

If yes, you can try to replace the line

docker_client = docker.from_env()

with

docker_client = docker.APIClient(base_url='unix://var/run/docker.sock')

That one has the create_host_config() method.

T .
  • 376
  • 3
  • 5