John Murphy
John Murphy

Reputation: 349

Will mounting a volume to a locations containing files of the same name overwrite those files or will they be used?

I'm looking for some help. If I use docker run to run a container and I have used -v to mount to a volume that already has files contained (these files are the files from a previous run of the container but with a config file edited). Will the container I run then use the contents of the files I have overwritten or will it use the files within the container anyways and disregard the files I have edited? I am running sudo docker run --rm -it -p "8000:8000" -v "/opt/stellar:/opt/stellar" --name stellar stellar/quickstart --testnet

And in /opt/stellar on my machine (AWS EC2) I have files alredy there included an edited stellar-core.cfg file.

Sorry if this is the a bit confusing. I am trying to explain what I mean as best I can. Thanks for any help.

Upvotes: 0

Views: 767

Answers (2)

grapes
grapes

Reputation: 8646

Strictly speaking, you are not talking about volumes but about bind mounts, unlike volumes, they allow you specify location on host machine.

The answer to your question is following:

  1. Bind mount always uses hosts content. If container had something in mounted folder, it will be overriden.

  2. Whenever you modify your folder from container, the changes persist on host (unless you bind ion readonly mode - then your changes would be rejected)

Upvotes: 1

David Maze
David Maze

Reputation: 159171

If you run:

docker run -v /host/directory:/container/directory ...

Then whatever is in the host directory will always hide whatever was in the image on that path, and if the application in the container makes changes in /container/directory, they will be reflected in the corresponding host directory.

If you update the image to have changes in the container directory, and you run the same docker run command, the host directory will still hide the image’s contents, and you won’t see those changes in the re-run container.

Upvotes: 1

Related Questions