question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

docker-py v2.0.0 Can't create container data volumes using client.containers.run & create

See original GitHub issue

https://docker-py.readthedocs.io/en/latest/containers.html: run method: for volumes it says:

volumes (dict or list) –

A dictionary to configure volumes mounted inside the container. The key is either the host path or a volume name, and the value is a dictionary with the keys:

    bind The path to mount the volume inside the container
    mode Either rw to mount the volume read/write, or ro to mount it read-only.

For example:

{'/home/user1/': {'bind': '/mnt/vol2', 'mode': 'rw'},
 '/var/www': {'bind': '/mnt/vol1', 'mode': 'ro'}}

This effectively means that you can’t create container data volumes, since you either have to create a volume 1st using docker create volume or use a host directory. There is no option to just specify a container folder.

The low-level API (https://docker-py.readthedocs.io/en/latest/api.html#module-docker.api.container) create_container still allows you to do this (since I was able to do this using the v1 of docker-py

From the docker run documentation https://docs.docker.com/engine/reference/commandline/run/:

  -v, --volume value                Bind mount a volume (default []). The format
                                    is `[host-src:]container-dest[:<options>]`.
                                    The comma-delimited `options` are [rw|ro],
                                    [z|Z], [[r]shared|[r]slave|[r]private], and
                                    [nocopy]. The 'host-src' is an absolute path
                                    or a name value.

Am I correct here that logic to support container data volumes is missing from client.containers.run & create? Or is there another way how to do this? Or are container data volumes being replaced by data volumes?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
RobbieClarkencommented, Jan 16, 2017

I believe there is also a bug with named volumes not being supported by DockerClient.containers.run:

>>> print(docker.__version__)
2.0.1
>>> client.containers.run('alpine', 'ls', volumes={'my-named-volume': {'bind': '/data', 'mode': 'ro'}})
Traceback (most recent call last):
[...]
docker.errors.APIError: 500 Server Error: Internal Server Error for url: http+docker://localunixsocket/v1.24/containers/create
("Invalid volume spec "my-named-volume": Invalid volume destination path: 'my-named-volume' mount path must beabsolute.")

(The volume had already been created with docker volume create --name my-named-volume.)

1reaction
bfirshcommented, Feb 7, 2017

Gosh, what a mess. Fixes for both things here: https://github.com/docker/docker-py/pull/1439

Sorry all!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Containers — Docker SDK for Python 6.0.1 documentation
command (str or list) – The command to run in the container. auto_remove (bool) – enable auto-removal of the container on daemon side...
Read more >
python - How to bind volumes in docker-py? - Stack Overflow
Here is how you would do it by using the create host config commands import docker client = docker.from_env() container = client.create_container( ...
Read more >
docker-sdk-python Documentation - Read the Docs
It lets you do anything the docker command does, but from within Python apps – run containers, manage containers, manage Swarms, etc.
Read more >
Examples using the Docker Engine SDKs and Docker API
This first example shows how to run a container using the Docker API. ... Also, if you are using swarm services, the containers...
Read more >
Docker Tutorial: What is Docker and How to Use it With Python
Container – a running instance that encapsulates required software. Containers are always created from images. A container can expose ports and volumes to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found