Persistent filesystem is one of the hardest parts of running a CMS or blog in the cloud. If you have ever tried running WordPress or Drupal on Docker or a PaaS environment before, you know what I am talking about. Each container or dyno is ephemeral (goes away when the container goes away) and when the dyno goes away, all your uploaded content goes away too.
Syncing Docker With NFS or Gluster
You can't easily Docker-ize NFS or Gluster. There are tutorials out there, and even a few containers in the index that say they work. But I could not get any of them working in the latest version of Docker. Even if you could in theory run NFS or Gluster in Docker, would you really want to? Who hasn't had trouble with those technologies here? Whether it is kernel patches or TCP ports, it is one thing or another. It is never easy. Wouldn't it be great if you could use a syncing technology that didn't require you to open ports or patch your kernel? Like Dropbox, but without the central server so you don't have to worry about your code being compromised?
Syncing Docker With Bittorrent Sync
Although BitTorrent Sync isn't open source, it does work really well to sync your servers for no cost and without a centralized server. A new open-source project called Syncthing is a promising alternative to BitTorrent Sync, but since it is not stable yet, we will show you how to use it after it becomes more stable. Here is how you can add syncing to your Docker app:
# Server 1 $ docker run -d --name btsync ctlc/btsync 90ecd4 $ docker logs 90ecd4 Starting btsync with secret: A645YG2WBR4DJI7J67ZK2EKD7XT44SYJ6 $ docker run -i -t --volumes-from btsync ubuntu bash root@2ff9f0194ac0:/# ls /data/ root@2ff9f0194ac0:/# touch /data/hello_world root@2ff9f0194ac0:/# ls /data/ hello_world
And on any other computer, you can run the
ctlc/btsync container with the secret from your first instance:
# Server 2 $ docker run -d --name btsync-client ctlc/btsync A645YG2WBR4DJI7J67ZK2EKD7XT44SYJ6 16e0e4 $ docker logs 16e0e4 Starting btsync with secret: A645YG2WBR4DJI7J67ZK2EKD7XT44SYJ6 $ docker run -i -t --volumes-from btsync-client ubuntu bash root@3053efa3c41f:/# ls /data/ hello_world
You only need to run one
ctlc/btsync container per virtual server. You can run as many containers that bind to that container's volumes through
--volume-from as you want. That way all your containers can share their ephemeral data locally AND across systems.
If you combine BitTorrent Sync with Docker, you can create a potent and powerful solution to the persistent filesystem problem without debugging NFS or kludging together an rsync solution. Data-only volumes are a great solution for shared filesystem within a single host, but when you want to build multi-host apps, using a solution like this can be an elegant way to scale.