Can't pass host device or volume to container if host path contains colon
See original GitHub issueSteps to reproduce
- Create a host path containing a colon
sudo mkdir /test:dir
- 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:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry for the confusion on the earlier thread.
mounts
andbinds
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.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)mounts
insteadHTH
Closing since this seems to have been answered.