Skip to content

Add timezone feature #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Based on Debian
FROM debian:buster

# Maintainer
Expand All @@ -16,7 +17,8 @@ LABEL org.label-schema.vcs-url "https://github.com/otherguy/docker-dropbo
LABEL org.label-schema.vcs-ref "${VCS_REF}"

# Required to prevent warnings
ENV DEBIAN_FRONTEND noninteractive
ARG DEBIAN_FRONTEND=noninteractive
ARG DEBCONF_NONINTERACTIVE_SEEN=true

# Install prerequisites
RUN apt-get update \
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This is the full command to start the Dropbox container. All volumes, environmen
are explained in the sections below.

$ docker run --detach -it --restart=always --name=dropbox \
-e "TZ=$(readlink /etc/localtime | sed 's#/var/db/timezone/zoneinfo/##')" \
-e DROPBOX_UID=$(id -u) \
-e DROPBOX_GID=$(id -g) \
-v "/path/to/local/settings:/opt/dropbox/.dropbox" \
Expand All @@ -49,6 +50,29 @@ The example below uses `id -u` and `id -g` to retrieve the current user's user i
-v "/path/to/local/dropbox:/opt/dropbox/Dropbox" \
[...]
otherguy/dropbox:latest

### Time Zones

It is also highly recommended to pass your local timezone settings into the container. This fixes the problem
of the host being on local time zone and container defaulting to `UTC` timezone. Dropbox is not checking time
zones when comparing file timestamps, leading to overwritten files and data loss.

You can pass your local timezone as an environment variable to the container: `-e "TZ=Australia/Brisbane"`

If you're on Linux 🐧, you can mount your `/etc/timezone` and `/etc/localtime` files into the container instead.

$ docker run --name=dropbox \
-v "/etc/timezone:/etc/timezone" \
-v "/etc/localtime:/etc/localtime" \
[...]
otherguy/dropbox:latest

For everyone else, especially users on macOS, getting your current timezone and passing it into the container
as an environment variable, is the simplest way:

$ docker run --name=dropbox \
-e "TZ=$(readlink /etc/localtime | sed 's#/var/db/timezone/zoneinfo/##')"
[...]
otherguy/dropbox:latest

### Enable LAN Sync
Expand Down Expand Up @@ -125,3 +149,7 @@ Originally forked from [`janeczku/dropbox`](https://hub.docker.com/r/janeczku/dr
## 🚧 Contributing

Bug reports and pull requests are welcome on GitHub at [`otherguy/docker-dropbox`](https://github.com/otherguy/docker-dropbox).

## ♥️ Acknowledgements

- [Tony Pan](https://github.com/tcpan) for [`#3`](https://github.com/otherguy/docker-dropbox/pull/3)
17 changes: 17 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#!/bin/bash
# This script is a fork of https://github.com/excelsiord/docker-dropbox

# Set TZ if not provided with enviromental variable.
if [ -z "${TZ}" ]; then
export TZ="$(cat /etc/timezone)"
else
if [ ! -f "/usr/share/zoneinfo/${TZ}" ]; then
echo "The timezone '${TZ}' is unavailable!"
exit 1
fi

echo "${TZ}" > /etc/timezone
ln -fs "/usr/share/zoneinfo/${TZ}" /etc/localtime
fi

# Set UID/GID if not provided with enviromental variable(s).
if [ -z "${DROPBOX_UID}" ]; then
export DROPBOX_UID=$(/usr/bin/id -u dropbox)
Expand Down Expand Up @@ -73,6 +86,10 @@ echo ""
# Set umask
umask 002

# Print timezone
echo "Using $(cat /etc/timezone) timezone ($(date +%H:%M:%S) local time)"
dpkg-reconfigure --frontend noninteractive tzdata

echo "Starting dropboxd ($(cat /opt/dropbox/bin/VERSION))..."
exec gosu dropbox "$@" &
pid="$!"
Expand Down