3

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

Philipp Schemel
  • 943
  • 8
  • 19
  • 1
    Rather than stopping try removing container 'docker-compose rm' and then re-run 'docker-compose up -d' with this it delete any files inside old container and always use new one available in mount folder. final command 'docker-compose rm -f && docker-compose up -d' – Rohan J Mohite Jul 26 '18 at 09:02
  • The problem is during build there will be some files copied into this directory, those default files. And due to this the files on the host will be overwritten. – Philipp Schemel Jul 26 '18 at 09:10
  • Ok, Then this just a suggestion - can you use IF ELSE condition when to copy default files or delete old files by passing an argument? this might resolve your issue. – Rohan J Mohite Jul 26 '18 at 09:16
  • Can you add some code to this question? For instance, is there an entrypoint script or something like that that's copying data out of the container? The behavior you describe is not the way Docker host-directory bind mounts usually work. Seeing the `docker-compose.yml` file would be helpful too. – David Maze Jul 26 '18 at 10:01

2 Answers2

3

maybe try configuring it as read only

docker run -v volume-name:/path/in/container:ro my/image
gCoh
  • 2,719
  • 1
  • 22
  • 46
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