docker-py: docker-py cannot bind local files into a container?

hi,all! I ofen bind host files into containers by using “-v /path/to/host/file:/container/file:ro”, when I using command line client. But now, I need to use docker-py to manage my containers. And I also need to do the same work:bind some host files into containers. And my code is like this (for example)


......
"volumes":["/etc/localtime"],
......
"binds":{
        "/etc/localtime":{
                 "bind":"/etc/localtime",
                 "ro":true
        }
},

unfortunately, problem emerged: APIError: 500 Server Error: Internal Server Error ( “Cannot start container 1c1…d7051: setup mount namespace mounting /var/lib/docker/vfs/dir/575…9f73 into /var/lib/docker/devicemapper/mnt/1c1f7f…1edd7051/rootfs/etc/localtime not a directory”)

what is the solution?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 20 (11 by maintainers)

Most upvoted comments

if host_config was deprecated in 1.2.3, where do I pass in binds now?

I think I’ve found the issue: can you try specifying the binds in the create_container call, like such

c.create_container(
    img, cmd, volumes=volumes, 
    host_config=docker.utils.create_host_config(binds=binds)
)

And see if that works?