Unable to run container with host's root volume mounted to a container
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
Description
I am failing to mount the host root within a container when calling DockerClient.containers.run() directly. Here is the failure i hit:
volumes = {"/":{'bind':'/test', 'mode':'rw'}}
client.containers.run(image=<my_image>, volumes=volumes, detach=True, name="voltest1")
docker.errors.APIError: 500 Server Error: Internal Server Error for url: http+docker://localunixsocket/v1.24/containers/create?name=voltest1 ("invalid volume spec "/": invalid volume specification: '/': invalid mount config for type "volume": invalid specification: destination can't be '/'")
If i change the host volume to anything else but root, it works.
Note that I can run this successfully from docker command:
sudo docker run -d -v '/':'/test' --name 'voltest1' <my_image>
Also, I was able to get this to work with the low level API - Create / Start - so not sure why run does not accept this.
Checking the history, looks like the deprecated library had this issue long ago and was fixed:https://github.com/ansible/ansible-modules-core/issues/3823
Has this regressed for the container.run now?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with DockerClient.containers.run() and compare how its volume argument is serialized with the low-level Create/Start API and the working docker run command. Reproduce the failure using the shown volumes mapping and verify that mounting host '/' to '/test' succeeds through containers.run() without changing other volume behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100