Docker-Compose mount volume overwrites host files

左心房为你撑大大i 提交于 2020-12-13 04:27:10

问题


I am mounting a directory from a CMS with content files inside a docker container.

The mounting works absolutely. The CMS got some basic files, which are copied into the mounted folder in the container during build. Then it will be mounted to a directory on the host. Now the files from the Container are also on the host. I can change them and they will be kept in sync.

If i restart my container docker-compose stop && docker-compose up -d the files on the host will be overwritten by the default ones from the container build.

Is there a possibility to force the local state of the file to overwrite the file in the container?

Kind regards


回答1:


maybe try configuring it as read only

docker run -v volume-name:/path/in/container:ro my/image



回答2:


You can set it as read only as gCoh answer. See the following for docker-compose:

volumes:
  - type: bind
    source: ./host-source-folder
    target: /container-folder
    read_only: true


来源:https://stackoverflow.com/questions/51534907/docker-compose-mount-volume-overwrites-host-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!