Posts | Tags | Archive

Dropbox in Docker with systemd

My CentOS 7 headless install of Dropbox recently quit syncing due to the new Dropbox linux requirements. Rather than try to hack it back together I found this great guide on running Dropbox in a Docker container which utilizes a pre-built container that can update itself, assuming Dropbox puts any more effort into their linux client. Cough. You can audit the security/operation of the container via its Dockerfile.

However one thing both the guide docs and container docs above leave out is automating operation of the Dropbox container via systemd, which of course is the default init system most places nowadays including my CentOS 7 and Ubuntu 18.04 bionic servers. The error I kept encountering was:

The name "dropbox" is already in use by container f9e5798a82e9

This is because all the guides suggest using the Docker parameter --name=dropbox which will only succeed the first time you issue the docker run command. When you restart the container via run instead of start it instructs docker to build a new container. Rebuilding the container is also when the Dockerfile would update to the latest version of Dropbox so we can't simply switch to start.

To get around this we use the systemd directive ExecStartPre=-/usr/bin/docker rm dropbox to remove any previous containers using the name dropbox, and additionally prefix the command with a - which tells systemd to ignore any failures reported by the command. ie: if there is no container to remove docker reports an error we don't care about.

  1. Update the unit file fields:
    MY_USERNAME, MY_UID, and MY_GID
  2. Drop it into:
    /etc/systemd/system/dropbox.service
  3. Reload, enable, and start Dropbox:
    systemctl daemon-reload && systemctl enable dropbox && systemctl start dropbox

This is working on my Ubuntu bionic box and I always welcome improvements, just comment on the gist!

© Justin Montgomery. Built using Pelican. Theme is subtle by Carey Metcalfe. Based on svbhack by Giulio Fidente.