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.

  • Is there a way to backup my docker environment
  • phantomJS on docker containers
  • How to send to stdin of a docker-py container?
  • Cannot remove docker images without tags/<none> tags
  • docker compose v3 mounting files
  • Docker - Install PDO Driver for PHP + Nginx
  • 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?

  • where should I put docker-compose.yml
  • Authenticate Google Cloud service account on docker image
  • What special precautions must I make for docker apps running as pid 1?
  • docker: installing a node.js application has issues, since docker runs as root
  • curl command for docker inspect
  • How can I run specific android app automatically by using Docker?
  • 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.