Run Dropbox client in a Docker container

Posted by Valentin Heidelberger on Wednesday, March 7, 2018 Tags: Docker Technology Linux Shell   6 minute read

Why

The official Dropbox client seems to be quite a mess on some Linux distributions. There are official packages for Ubuntu/Debian and Fedora/RedHat, which seem to be pretty stable, but at least in my distribution (which builds it from source) it is unusable. Considering the plethora of distros, that are out there, it is a good idea to not waste much time trying to get it to work on your particular distro, but to simply use a Docker container.

How

Implementing this is actually incredibly simple. Just add the following two shell aliases to your .bashrc, .zshrc or whatever:

   alias dropbox="docker exec -it dropbox dropbox"
   alias dropbox-start="docker run -d --restart=always --name=dropbox -v /home/val/Dropbox:/dbox/Dropbox -v /home/val/.dropbox:/dbox/.dropbox -e DBOX_UID=1000 -e DBOX_GID=100 janeczku/dropbox"

The alias dropbox-start pulls the docker image janeczku/dropbox from Dockerhub and runs it with restart set to always. This makes sure, that the container is immediately restarted, if it crashes and also starts it on system boot. Also the command mounts the folders /home/val/Dropbox and /home/val/.dropbox at the mountpoints /dbox/Dropbox and /dbox/.dropbox inside the container and gives the container two variables containing the UID and GID to use for read/write operations.

Don’t forget to replace the folder paths with your desired paths and the variables DBOX_UID and DBOX_GID with your uid/gid; otherwise Dropbox might have a permission problem. Don’t give it the UID “0”, because that is root and you just don’t wan’t something to run with root privileges, if it doesn’t need to.

Make sure, that the folders /home/user/Dropbox and /home/user/.dropbox do not exist before you execute dropbox-start the first time. Dropbox insists on creating these folders itself and will simply crash over and over again if it can’t. I spent quite some time debugging until I found that out actually…

dropbox-start should print a container ID to your screen, if it was successful. You can also use “docker ps” to check, if and how long the container’s running:

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
91eee27158bb        janeczku/dropbox    "/root/run"         3 days ago          Up 4 hours          17500/tcp           dropbox

Once the container is up and running, you need to check it’s logs to link the client to your Dropbox account. Dropbox keeps printing a link to the logs until you connect it to a account:

$ docker logs --follow 91eee27158bb
Checking for latest Dropbox version...
Latest   : 44.4.58
Installed: 11.4.21
Downloading Dropbox v44.4.58...
######################################################################## 100.0%
Installing new version...
Dropbox updated to v44.4.58
Starting dropboxd (44.4.58)...
dropbox: locating interpreter
!! dropbox: failed to create log file (Permission denied)!
dropbox: initializing
dropbox: initializing python 2.7.11
dropbox: setting program path '/opt/dropbox/dropbox-lnx.x86_64-44.4.58/dropbox'
dropbox: setting home path '/opt/dropbox/dropbox-lnx.x86_64-44.4.58'
dropbox: setting python path '/opt/dropbox/dropbox-lnx.x86_64-44.4.58:/opt/dropbox/dropbox-lnx.x86_64-44.4.58/python-packages-27.zip'
dropbox: python initialized
dropbox: running dropbox
dropbox: setting args
dropbox: applying overrides
dropbox: running main script
dropbox: load fq extension '/opt/dropbox/dropbox-lnx.x86_64-44.4.58/cryptography.hazmat.bindings._constant_time.so'
dropbox: load fq extension '/opt/dropbox/dropbox-lnx.x86_64-44.4.58/cryptography.hazmat.bindings._openssl.so'
dropbox: load fq extension '/opt/dropbox/dropbox-lnx.x86_64-44.4.58/cryptography.hazmat.bindings._padding.so'
dropbox: load fq extension '/opt/dropbox/dropbox-lnx.x86_64-44.4.58/psutil._psutil_linux.so'
dropbox: load fq extension '/opt/dropbox/dropbox-lnx.x86_64-44.4.58/psutil._psutil_posix.so'
dropbox: load fq extension '/opt/dropbox/dropbox-lnx.x86_64-44.4.58/linuxffi.pthread._linuxffi_pthread.so'
dropbox: load fq extension '/opt/dropbox/dropbox-lnx.x86_64-44.4.58/tornado.speedups.so'
dropbox: load fq extension '/opt/dropbox/dropbox-lnx.x86_64-44.4.58/cpuid.compiled._cpuid.so'
dropbox: load fq extension '/opt/dropbox/dropbox-lnx.x86_64-44.4.58/linuxffi.resolv.compiled._linuxffi_resolv.so'
dropbox: load fq extension '/opt/dropbox/dropbox-lnx.x86_64-44.4.58/posixffi.libc._posixffi_libc.so'
dropbox: load fq extension '/opt/dropbox/dropbox-lnx.x86_64-44.4.58/linuxffi.sys.compiled._linuxffi_sys.so'
dropbox: load fq extension '/opt/dropbox/dropbox-lnx.x86_64-44.4.58/librsyncffi.compiled._librsyncffi.so'
This computer isn't linked to any Dropbox account...
Please visit https://www.dropbox.com/cli_link_nonce?nonce=22a3a1f3d92077590f37fcd5ae1aa687 to link this device.
This computer isn't linked to any Dropbox account...

Of course the nonce will be different in your logs. Open the link in your web browser to authenticate and connect. Once the client has been successfully linked to your account a message will appear in the logs and the client will start syncing:

...
Please visit https://www.dropbox.com/cli_link_nonce?nonce=22a3a1f3d92077590f37fcd5ae1aa687 to link this device.
This computer is now linked to Dropbox. Welcome Valentin

The alias dropbox simply executes the “dropbox” command inside the container. With the various subcommands of “dropbox” you can check lots of things. E.g. if it’s currently synchronizing something:

$ dropbox status
Up to date

Calling the “dropbox” alias without a subcommand will output a list of available subcommands:

$ dropbox
Dropbox command-line interface

commands:

Note: use dropbox help <command> to view usage for a specific command.

 status       get current status of the dropboxd
 throttle     set bandwidth limits for Dropbox
 help         provide help
 puburl       get public url of a file in your dropbox's public folder
 stop         stop dropboxd
 running      return whether dropbox is running
 start        start dropboxd
 filestatus   get current sync status of one or more files
 ls           list directory contents with current sync status
 autostart    automatically start dropbox at login
 exclude      ignores/excludes a directory from syncing
 lansync      enables or disables LAN sync
 sharelink    get a shared link for a file in your dropbox
 proxy        set proxy settings for Dropbox

Summary

Containerizing apps is a very nice thing in general, because it makes the stuff inside the container basically independent from what’s going on outside (system updates, new/old versions of libraries, etc.). However, you should always check what’s going on in the Docker images, before giving it’s container access to your private data. Especially, if you don’t know the author(s). The source for the docker image used above is available on GitHub and built automatically from there, so you can actually check what’s going on. I know it’s a bit ironic to talk about privacy in an article about Dropbox but remember: everyone can upload their stuff to Dockerhub and theoretically hide something inside.

So, embrace simplicity, but keep your eyes peeled.