3

I am learning Docker of late and I have a few doubts with dockers volume. I want a few folders on my container to be mounted on my host machine, when the container starts and use the same volume from my host machine there on forward whenever the container is started.

I was using -v /path/on/host:/path/on/container. But as per my understanding, since the directory on the host is empty and is mounted, the path in the container also empty and hence any configurations files on the container on this path is also empty.

How do I set up volumes such that as the container starts, the files and directories created on the container appear on the host volume also?

nidHi
  • 833
  • 3
  • 10
  • 21

1 Answers1

0

You could pre-create the config files you need and putting them on the path which is then mounted to the container or you could start the container without a volume mounted and copy the config to your physical host and then mount them as volume to the container.

Sergiu
  • 2,928
  • 3
  • 27
  • 37
  • I pre-created all the files before hand and then mounted the volume to the container. Now the container has all the necessary files. But it is not able to access a file that is created by the host. Is there a way to retain the ownership of the host even in the container? Or a way to give sudo ownership to all files in the container for the user created in the container itself? – nidHi Apr 07 '16 at 11:30
  • I understand, the container uses your first host user inside the container. Say for example, on my host I have a user called sergiu that user will be used inside the container. Also you can start the container with privileges as follows: docker run --privileged. Moreover, I came across this which is explaining how the privileges works inside and outside the container: http://stackoverflow.com/questions/26500270/understanding-user-file-ownership-in-docker-how-to-avoid-changing-permissions-o – Sergiu Apr 07 '16 at 13:56
  • I am trying to run gerrit on this container. I followed the link posted. Docker is working as expected with the new UID's and GID's. Gerrit configuration is posing a few problems. Am working on it. Thanks for the input. – nidHi Apr 12 '16 at 05:16