你可以通过
sh
somefile
一些文字
在文件中。
只需多次运行此命令即可进行测试。
docker run \
--rm \
--mount source=shared-volume,target=/some-directory-with-content/ \
alpine \
sh -c "touch /some-directory-with-content/somefile && cat /some-directory-with-content/somefile && echo "some-text" >> /some-directory-with-content/somefile"
这是预期结果:
neo@neo-desktop:shared-vol-demo$ docker run --rm --mount source=shared-volume,target=/some-directory-with-content/ alpine sh -c "touch /some-directory-with-content/somefile && cat /some-directory-with-content/somefile && echo "some-text" >> /some-directory-with-content/somefile"
neo@neo-desktop:shared-vol-demo$ docker run --rm --mount source=shared-volume,target=/some-directory-with-content/ alpine sh -c "touch /some-directory-with-content/somefile && cat /some-directory-with-content/somefile && echo "some-text" >> /some-directory-with-content/somefile"
some-text
neo@neo-desktop:shared-vol-demo$ docker run --rm --mount source=shared-volume,target=/some-directory-with-content/ alpine sh -c "touch /some-directory-with-content/somefile && cat /some-directory-with-content/somefile && echo "some-text" >> /some-directory-with-content/somefile"
some-text
some-text