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 - instead of just directories - from the host machine.
$ docker run --rm -it -v ~/.bash_history:/.bash_history ubuntu /bin/bash
This will drop you into a bash shell in a new container, you will have your bash history from the host and when you exit the container, the host will have the history of the commands typed while in the container.
tom@u ~/project $ docker run --rm -it -v file.json:/file.json test
drwxr-xr-x 9 root root 4.0K Dec 7 12:58 .
drwxr-xr-x 63 root root 4.0K Dec 7 12:58 ..
drwxr-xr-x 2 root root 4.0K Dec 4 16:10 file.json
CMD ["ls", "-lah", "/test"]
test is the name of your image that you have built with '
docker build -t test', not a
CMD ["ls", "-lah", "/"] or CMD ["cat", "/file.json"]
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)