Docker Volumes mounting issue

I am trying to dynamically mount a volume from the container to the host and it works but there is a hitch. I am using the following command:

    docker run -it --name Test1 -v $HOME/.myapp_configs/specificConfig.txt:/bin/specificConfig.txt:rw docker-image /bin/bash 

The issue lies in that if the mount point on the host does not exist the docker command creates it but assigns it root:root rather than $USER:$USER like I would expect. I gather that this is more than likely a direct result of the namespace mapping issue that has been identified with Docker.

  • How to mount volume for docker container via yaml manifest?
  • Supervisord in Docker + AWS Elastic Beanstalk can't accept non-alphanumeric environment variables
  • Mounted docker volumes corrupting files
  • Docker network does not work with bash entrypoint
  • how to “docker run” a shell session on a minimal linux install and immediately tear down the container?
  • Docker 1.12 Swarm Overlay Network Published Port
  • Does anyone have any thoughts on how I can force the host mount point to be created with the appropriate permissions? i.e.

        drwxr-xr-x. 3 $USER $USER  31 Aug 21 15:02  ~/.myapp_configs/specificConfig.txt
    

    instead of…

        drwxr-xr-x. 3  root  root  31 Aug 21 15:02  ~/.myapp_configs/specificConfig.txt 
    

    Thanks,

    Bruce

  • Errno::EACCES creating rails project using Docker Rails image
  • docker run from systemd service starts but exits immediately, and restarts, but docker run from shell works fine
  • Docker port mapping
  • Virtualbox inside docker container without host dependency
  • Searching a Docker Image for a particular file
  • How to generate a certificate for AWS EC2 instance part of AWS ECS ( Docker)
  • One Solution collect form web for “Docker Volumes mounting issue”

    What about making sure the file exists before running the container?

    the command could look like:

    test -f $HOME/.myapp_configs/specificConfig.txt || touch $HOME/.myapp_configs/specificConfig.txt
    docker run -it --name Test1 -v $HOME/.myapp_configs/specificConfig.txt:/bin/specificConfig.txt:rw docker-image /bin/bash
    

    explanation:

    • test -f <some file> will have exit status 0 if the file exists
    • || will execute the following command only if the previous command exit status is different than 0
    • touch <some file> modify an existing file modification time, or (and this is our case) create an empty file

    Of course, if inside your container lies some code that acts differently whether the file exists or not, then you would have to adapt that code to check if the file is empty instead.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.