Search code examples
dockerdocker-volume

Docker initialize host mounted volume


I want to create a docker image for a software that need a persistent data volume which has to be initialized with some specific files and folders and I think you could reach that be creating a volume in the dockerfile after the creation of the files.

But my problem is, that I want to access the files direct from the host system, but it seems that there is no way to initialize the host folder like the named volume would be.

Does anybody know a way to achieve such an initialization?


Solution

  • I now found a solution for this problem. The point is that only named volumes are initialized in this way, but, at least with docker-compose, you can specify a named volume which refers to a given folder on host and will be initialized:

    volumes:
      my_volume:
        driver: local
        driver_opts:
          type: none
          device: ./data_volume_dir
          o: bind