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.

Can't pass host device or volume to container if host path contains colon

See original GitHub issue

Steps to reproduce

  1. Create a host path containing a colon
sudo mkdir /test:dir
  1. Use “recommended dictionary notation” to pass volume to container
import docker
client = docker.from_env()
vols={'/test:dir': {'bind': '/test'}}
client.containers.create("ubuntu:latest", volumes=vols)

Error

APIError: 500 Server Error: Internal Server Error ("invalid volume specification: '/test:dir:/testdir:rw'")

Stack trace

APIError                                  Traceback (most recent call last)                                                                                       <ipython-input-11-9017b6f19e04> in <module>()                                                                                                                            
----> 1 client.containers.create("ubuntu:latest", volumes=vols)                                                                                                          
                                                                                                                                                                         
/home/kavefish/Documents/devel/docker-py-bug/docker/models/containers.pyc in create(self, image, command, **kwargs)                                                      
    822         kwargs['version'] = self.client.api._version                                                                                                             
    823         create_kwargs = _create_container_args(kwargs)                                                                                                           
--> 824         resp = self.client.api.create_container(**create_kwargs)
    825         return self.get(resp['Id'])
    826

/home/kavefish/Documents/devel/docker-py-bug/docker/api/container.pyc in create_container(self, image, command, hostname, user, detach, stdin_open, tty, ports, environm$
nt, volumes, network_disabled, name, entrypoint, working_dir, domainname, host_config, mac_address, labels, stop_signal, networking_config, healthcheck, stop_timeout, r$
ntime)
    408             stop_timeout, runtime
    409         )
--> 410         return self.create_container_from_config(config, name)
    411
    412     def create_container_config(self, *args, **kwargs):

/home/kavefish/Documents/devel/docker-py-bug/docker/api/container.pyc in create_container_from_config(self, config, name)
    419         }
    420         res = self._post_json(u, data=config, params=params)
--> 421         return self._result(res, True)
    422
    423     def create_host_config(self, *args, **kwargs):

/home/kavefish/Documents/devel/docker-py-bug/docker/api/client.pyc in _result(self, response, json, binary)
    229     def _result(self, response, json=False, binary=False):
    230         assert not (json and binary)
--> 231         self._raise_for_status(response)
    232
    233         if json:

/home/kavefish/Documents/devel/docker-py-bug/docker/api/client.pyc in _raise_for_status(self, response)
    225             response.raise_for_status()
    226         except requests.exceptions.HTTPError as e:
--> 227             raise create_api_error_from_http_exception(e)
    228
    229     def _result(self, response, json=False, binary=False):

/home/kavefish/Documents/devel/docker-py-bug/docker/errors.pyc in create_api_error_from_http_exception(e)
     29         else:
     30             cls = NotFound
---> 31     raise cls(e, response=response, explanation=explanation)

APIError: 500 Server Error: Internal Server Error ("invalid volume specification: '/test:dir:/testdir:rw'")

Environment

docker-py: 3.3.0 Python: 2.7.15rc1 engine: 17.12.1-ce Ubuntu 18.04

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shin-commented, May 31, 2018

Sorry for the confusion on the earlier thread.

  1. mounts and binds are 2 different things, as explained here (in the context of the CLI). mounts is more modern and a better choice 99% of the time.
  2. Because of the way the binds API was designed, {'/test:dir': {'bind': '/test'}} has to be transformed into ['test:dir:/test'], which the daemon fails to parse (as it expects the colon to be a path separator). This is not a SDK issue. (See here for the Docker daemon API)
  3. As @thaJeztah pointed out, the correct approach to this problem is to use mounts instead
import docker
c = docker.from_env()
mnt = docker.types.Mount(type='bind', source='/tmp/colon:colon/', target='/colon')
ctnr = c.containers.create('busybox', mounts=[mnt]) # <Container: 38869806cb>

HTH

0reactions
ijccommented, Apr 5, 2019

Closing since this seems to have been answered.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot mount volume in docker container when directory ...
Colons are currently not supported when specifying directory mappings via -v , and it seems you cannot escape them either.
Read more >
Volumes - Docker Documentation
While bind mounts are dependent on the directory structure and OS of the host machine, volumes are completely managed by Docker. Volumes have...
Read more >
Guide to Docker Volumes - Baeldung
Starting a Container with a Volume​​ The -v option contains three components, separated by colons: Source directory or volume name. Mount point ...
Read more >
How To Share Data between Docker Containers - DigitalOcean
Note: We can even look at the data on the host at the path listed ... Docker won't let us remove a volume...
Read more >
Container permission denied: How to diagnose this error
Many users' only choice is to run with --privileged mode. When the container runs fine with --privileged , users need to understand what...
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