The objective of this blog post is to explain how you can configure unlimited dropbox accounts on single PC using a container-based virtualization technology called Docker.
This post of course is going to be tricky for a non-technical audience, for the approach itself being technical, but at the end of this blog post I will put together a sequence of commands for easy follow.
Please be informed that this blog post is not a guide to Docker so I won't dwelling into the details but nevertheless will be bringing up features of Docker that makes us achieve the objective. Also, all the commands that I will be demonstrating here were executed on linux. Equivalent commands could be found in docker documentations for respective platforms.
Ofcourse you can have multiple dropbox accounts on a single machine if you are a Dropbox Business customer. There in fact is a dedicated page (Can I have multiple Dropbox accounts?) by the community help center that explains the same. But IMHO it's a bit expensive if you simply want to have multiple accounts configured on a single PC and not really need the rest of the dropbox's premium features.
This, however, is not the only option. You can, of course, try multiple web logins, folder sharing on dropbox, multiple user accounts on your OS, etc. as explained in various articles online, such as, this one. But they all come with their own inconveniences.
What if we could run multiple instances of dropbox on the same machine?
Let's try it out!
On a linux machine you can install and run an instance of dropbox via command line as explained in the dropbox linux installation guide, like so:
$ cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf - $ ~/.dropbox-dist/dropboxd
Now, however, if you try to install and run another instance of dropbox on the same machine, you will get following response!
Another instance of Dropbox is running!
Oops! This clearly seems like a dead end. But don't curse dropbox for this yet. This in fact is a typical case of Software Conflict due to a programming bug or when two programs compete for the same resources (memory, peripheral device, register, network port, etc). Here are some common conflict problems (cited from Docker In Action):
- Two programs want to bind to the same network port.
- Two programs use the same temporary filename, and file locks are preventing that.
- Two programs want to use different versions of some globally installed binary.
- Two copies of the same program want to use the same PID file.
- A second program you installed modified an environment variable that another program uses. Now the first program breaks.
All these conflicts arise when one or more programs have a common dependency but can't agree to share or have different needs.
Well this is exactly where Docker comes to the rescue!
Docker is basically a tool to package your application and all it's dependencies together in a loosely isolated environment called a container. An environment with it's own set of namespaces:
- The pid namespace: Process isolation (PID: Process ID).
- The net namespace: Managing network interfaces (NET: Networking).
- The ipc namespace: Managing access to IPC resources (IPC: InterProcess Communication).
- The mnt namespace: Managing filesystem mount points (MNT: Mount).
- The uts namespace: Isolating kernel and version identifiers. (UTS: Unix Timesharing System).
Dropbox instances running separately in such containers will never compete for resources against each other thereby resolving the typical issue of Software Conflicts. All we would need now is a tool to help us spin up as many containerized dropbox instances as we would want on the same machine.
You guessed it right, Docker being just the perfect fit!
Let's try it out!
Before you can start creating containers you would first need to install docker itself on your machine. For your specific platform, find detailed installation guide here and make sure you have appropriate permissions to execute these commands.
$ curl -fsSL https://get.docker.com -o get-docker.sh | sh
Pull Docker Dropbox Image
A Docker image is a read-only template with instructions for packaging your applications and creating Docker containers. Instead of creating a docker image that packages dropbox ourselves we would be using one already available on DockerHub.
Pull this Docker image on your machine, like so:
$ docker pull janeczku/dropbox
Before we start spinning up containers from the docker image that we just pulled, there are two important things that we would need to take care of. We need to tell dropbox instance to sync "a directory" on our machine to a particular dropbox account. We also would need to specify a Container Restart Policy.
A Volume is a designated directory in a container, which is designed to persist data, independent of the container's life cycle. It is a mount point on the container's directory tree where a portion of the host directory tree is mounted.
For our purpose, all we would need to do is to map a desired directory on our host machine to the volume
/dbox/Dropbox that the docker image,
janeczku/dropbox, makes available by default for every container spun from it and dropbox takes care of syncing whatever is written to that directory.
/home/shivam/ddsk1 is the directory on my machine that I want dropbox to sync to one of my dropbox accounts.
Wouldn't it be nice if every time you restart your system, your docker dropbox container instances are also started automatically? This could be achieved by specifying the Container Restart Policy as an argument to the command that creates docker.
It's time to create docker dropbox container instances.
$ docker run -d --restart=always --name=dropbox1 --volume=/home/shivam/ddsk1:/dbox/Dropbox janeczku/dropbox
Link Your Machine To Dropbox Account
Once your container is created, the dropbox instance running inside this container will start logging you a link to follow in container logs so as to register your machine to your dropbox account.
You can follow those logs, like so:
$ docker logs dropbox1
Go ahead and copy paste similar link from container logs in a browser to register your machine to one of your dropbox accounts.
This computer isn't linked to any Dropbox account...
Please visit https://www.dropbox.com/cli_link_nonce?nonce=61df1d68e00bf41198699824d4d69438 to link this device.
An important thing though to remember is that you would need to login to different dropbox accounts on your browser every time you copy paste the registration link so as to register the same machine to different accounts. Also, the registration link keeps changing at a certain time interval, so make sure you are coping the latest one.
After registering your machine to your dropbox account, you may need to restart your container if it doesn't already starts syncing, like so:
$ docker restart dropbox1
You can always check the sync status using following command:
$ docker exec -it dropbox1 dropbox status
There you go! You have a successfully up and running docker dropbox instance on your machine. To spin up multiple such docker dropbox instances on the same machine, all you need to do is to repeat steps described above, in the same order.