Search code examples
python-2.7dockerdocker-volumedockerpy

running and sharing a host folder from a container using docker-py


I want to run a container using the python docker with a persistent shared folder. The command line to do so is as follow :

docker run --rm -ti -v /home/docker:/container_shared_folder ubuntu:14.04 bash -c my_command

can you please help me to realize that using docker-py ?

Regards !


Solution

  • Can you try specifying volumes in the following manner :

    cmd_stdout = client.containers.run(
    my_container, 
    my_command, 
    remove=True, 
    volumes= 
    {'/home/user/location1': {'bind': '/mnt/vol1', 'mode': 'rw'},
     '/home/user/location2': {'bind': '/mnt/vol2', 'mode': 'rw'}
    }
    )