How to mount a single file in a volume

后端 未结 14 1020
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 10:16

I am trying to dockerize a PHP application. In the dockerfile, I download the archive, extract it, etc.

Everything works fine. However, if a new version gets released

14条回答
  •  一整个雨季
    2020-11-27 10:27

    I had been suffering from a similar issue. I was trying to import my config file to my container so that I can fix it every time I need without re-building the image.

    I mean I thought the below command would map $(pwd)/config.py from Docker host to /root/app/config.py into the container as a file.

    docker run -v $(pwd)/config.py:/root/app/config.py my_docker_image
    

    However, it always created a directory named config.py, not a file.

    while looking for clue, I found the reason(from here)

    If you use -v or --volume to bind-mount a file or directory that does not yet exist on the Docker host, -v will create the endpoint for you. It is always created as a directory.

    Therefore, it is always created as a directory because my docker host does not have $(pwd)/config.py.

    Even if I create config.py in docker host. $(pwd)/config.py just overwirte /root/app/config.py not exporting /root/app/config.py.

提交回复
热议问题