Docker: I'm not able to make working a volume binding at runtime

I’m executing my image in this way:

docker run -it --rm my_image -v ~/.ssh/id_rsa:/home/realtebo/.ssh/id_rsa:ro

So I expect that my private rsa key is copied at runtime when executing.

  • HTTP Request from Dockerfile not successful
  • Should I create a volume for project files when using Docker with git?
  • Can I update the hostname of a Docker Node?
  • Dockerized Mongo takes ages to load then doesn't run mongo
  • Managing authentication across micro-services
  • Moving from Vagrant to Vagrant with Docker
  • This is the shell script I used as entrypoint

    pwd
    ls -la ~/.ssh
    

    At runtime I got this

    /home/realtebo
    total 12
    drwxr-xr-x 2 realtebo realtebo 4096 Jan 19 08:20 .
    drwxr-xr-x 3 realtebo realtebo 4096 Jan 19 08:37 ..
    -rw-r--r-- 1 realtebo realtebo  393 Jan 19 08:20 known_hosts
    

    So the working dir and the user are ok.

    note: known_hosts is created at build time

    Why cannot I get /home/realtebo/.ssh/id_rsa as I expect ?

    I do some debugging using docker inspect <container_name. I discovered that :

    "HostConfig": {
            "Binds": null,
     ....
    

    But what’s the problem?

  • Docker ps disappeared after restart system
  • Ping docker containers on different hosts with ip addresses
  • Cloned git not in Docker Volume?
  • Using RabbitMQ in for communication between different Docker container
  • Composer doesn't see GD extension
  • How to mount a directory inside a docker container on linux host
  • One Solution collect form web for “Docker: I'm not able to make working a volume binding at runtime”

    Solution: exchange -v flag and image_name.
    Image name must always be the last argument (followed by optional cmd to execute)

    So instead of

    docker run -it --rm my_image -v ~/.ssh/id_rsa:/home/realtebo/.ssh/id_rsa:ro
    

    I need to execute in this way:

    docker run -it --rm v ~/.ssh/id_rsa:/home/realtebo/.ssh/id_rsa:ro my_image
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.