How to ensure two docker containers don't process the same file?

Viewed 238

So I have two services A and B in a swarm. A has 5 instances and so does B. They both access files from a common mount. If I put a 100 files in this mount, how do I ensure that the files A and B pick (maybe 50 each) are mutually exclusive i.e the file doesn't get processed twice? Additionally how would i ensure this for two instances of the same service?

1 Answers

With the same methods that you would employ with a shared mount, when there are multiple processes on the same host/or different hosts with access to it. There is little that is unique about containers in this aspect.

You need to apply locks to prevent simultaneous writes. And make sure you always reading the latest data from the volume.

Related