0

Different than this one here.

I want to link multiple NFS mounts that point to the same local location in a docker-compose image. I put the following lines in a docker-compose file:

volumes:
  nfs3:
    driver: local
    driver_opts:
      type: nfs
      o: addr=172.16.20.5,rw
      device: ":/tmp/mount1"
  nfs4:
    driver: local
    driver_opts:
      type: nfs
      o: addr=172.16.20.6,rw
      device: ":/tmp/mount2"

And then in the services part, I have a postgres instance that has the following volume config:

volumes:
  - nfs3:/bitnami
  - nfs4:/bitnami

Unfortunately, when I write to /bitnami, it only writes to /tmp/mount2 and not /tmp/mount1. Is there a good way to be able to write to both NFS mounts?

AndreasKralj
  • 463
  • 4
  • 23

1 Answers1

1

The docker volume system uses the linux mount interface. Only one thing can be mounted at a time for a particular location. The most recent mount is the mount that is accessible.

This question discusses what happens to files that were in a particular location when a mount happens.

In your example, if files are only showing up on your /tmp/mount2 nfs share, then that was the most recent filesystem to be mounted at /bitnami.

Similarly, if I try to mount two USB drives at the same location on a linux host, only the most recently mounted one will be the one available at that location.

programmerq
  • 6,262
  • 25
  • 40
  • Gotcha, thanks for the answer! Do you recommend an alternate method of storing data from one Docker container to multiple devices at the same time? – AndreasKralj Mar 08 '19 at 20:40
  • 1
    I don't see this as a docker specific question. Docker is just a thing that starts processes and sets up mounts for you, so you could restate your question as follows: How would one store data written by my process/application in more than one location?" There are lots of answers-- unison, rsync, change your application to write in two places, etc... – programmerq Mar 08 '19 at 20:42
  • Thanks. I'll look into those. The specific application I'm using is postgresql so I'll try and find a way to do that with postgresql. – AndreasKralj Mar 08 '19 at 20:43
  • Postgres does have replication features built in, but that usually means that you will be running different instances of postgres. What is your motivation to have one postgres with data in multiple places? It isn't really a common postgres question. – programmerq Mar 08 '19 at 20:45
  • The main motivation is so that if one NFS server goes down, we have another that the postgresql container will write to as permanent storage. The reason to have the external storage on NFS servers is so that if the server hosting the Docker container goes down, we'll still have the posgresql data. If there's a better way, please let me know. – AndreasKralj Mar 08 '19 at 20:50