Single file volume mounted as directory in Docker

前端 未结 6 1777
春和景丽
春和景丽 2020-12-23 19:00

Docker documentation says that it\'s possible to mount a single file into a Docker container:

The -v flag can also be used to mount a single file - in

6条回答
  •  孤独总比滥情好
    2020-12-23 19:38

    test is the name of your image that you have built with 'docker build -t test', not a /test folder.

    Try a Dockerfile with:

    CMD ["ls", "-lah", "/"]
    or
    CMD ["cat", "/file.json"]
    

    And:

    docker run --rm -it -v $(pwd)/file.json:/file.json test
    

    Note the use of $(pwd) in order to mount a file with its full absolute path (relative paths are not supported)

    By using $(pwd), you will get an absolute path which does exists, and respect the case, as opposed to a file name or path which might not exist.
    An non-existing host path would be mounted as a folder in the container.

提交回复
热议问题