├── config └── setup.sh ├── Makefile ├── .gitignore ├── Dockerfile ├── README.md ├── LICENSE └── service.sh /config/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd /home/cloud-admin 4 | chown cloud-admin:cloud-admin /home/cloud-admin 5 | sudo --user=cloud-admin -- tar xzf /config/dropbox.tar.gz 6 | sudo --user=cloud-admin --login -- .dropbox-dist/dropboxd 7 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | start: 2 | bash service.sh start 3 | .PHONY: start 4 | 5 | stop: 6 | bash service.sh stop 7 | .PHONY: stop 8 | 9 | install: 10 | bash service.sh install 11 | .PHONY: install 12 | 13 | uninstall: 14 | bash service.sh uninstall 15 | .PHONY: uninstall 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Compiled Dynamic libraries 8 | *.so 9 | *.dylib 10 | *.dll 11 | 12 | # Compiled Static libraries 13 | *.lai 14 | *.la 15 | *.a 16 | *.lib 17 | 18 | # Executables 19 | *.exe 20 | *.out 21 | *.app 22 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:14.04 2 | MAINTAINER Kentaro Imajo 3 | RUN useradd --home-dir=/home/cloud-admin --create-home --uid=20601 --user-group --shell=/bin/bash cloud-admin 4 | RUN apt-get update -qq && apt-get install -y wget 5 | RUN mkdir -p /config 6 | RUN wget -O /config/dropbox.tar.gz "https://www.dropbox.com/download?plat=lnx.x86_64" 7 | ADD config/setup.sh /config/setup.sh 8 | CMD sudo --user=cloud-admin --login -- /home/cloud-admin/.dropbox-dist/dropboxd 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Dropbox in Docker 2 | ================= 3 | 4 | Install Dropbox inside Docker. 5 | 6 | How to Install 7 | -------------- 8 | 9 | Run the following command. This command will show a URL to activate Dropbox. Once you activate Dropbox during running the command, you should kill it because it runs a temporary container just for activating Dropbox. 10 | 11 | ```sh 12 | git clone https://github.com/imos/docker-dropbox docker-dropbox 13 | cd docker-dropbox && make install 14 | ``` 15 | 16 | How to Use Docker-Dropbox 17 | ------------------------- 18 | 19 | Run the following command: 20 | 21 | ```sh 22 | make start 23 | ``` 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Kentaro IMAJO 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /service.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | : ${SERVICE:=dropbox} 4 | : ${CPU:=100} 5 | : ${MEMORY:=100M} 6 | : ${DISK:=5G} 7 | 8 | set -e -u 9 | 10 | if ! test "$(whoami)" = 'root'; then 11 | echo 'this script must run as root.' >&2 12 | exit 1 13 | fi 14 | 15 | DockerRun() { 16 | DOCKER_FLAGS+=( 17 | --volume="/storage/${SERVICE}:/home/cloud-admin" 18 | --memory="${MEMORY}" --cpu-shares="${CPU}" 19 | ) 20 | docker run "${DOCKER_FLAGS[@]}" "${SERVICE}" "$@" 21 | } 22 | 23 | Mount() { 24 | if ! mountpoint -q "/storage/${SERVICE}"; then 25 | if [ ! -f "/storage/${SERVICE}/image.dmg" ]; then 26 | echo "install docker-dropbox: './service.sh install'" >&2 27 | exit 1 28 | fi 29 | e2fsck -y -f "/storage/${SERVICE}/image.dmg" 30 | resize2fs "/storage/${SERVICE}/image.dmg" "${DISK}" 31 | mount -t auto -o loop "/storage/${SERVICE}/image.dmg" "/storage/${SERVICE}" 32 | fi 33 | chown 20601:20601 "/storage/${SERVICE}" 34 | } 35 | 36 | Start() { 37 | if docker top "${SERVICE}" >/dev/null 2>/dev/null; then 38 | echo 'docker is already running.' >&2 39 | fi 40 | Mount 41 | DOCKER_FLAGS=(--name="${SERVICE}" --hostname="${SERVICE}" --detach) 42 | DockerRun "$@" 43 | } 44 | 45 | Stop() { 46 | docker kill "${SERVICE}" >/dev/null || true 47 | docker rm "${SERVICE}" >/dev/null || true 48 | if mountpoint -q "/storage/${SERVICE}"; then 49 | fuser --kill "/storage/${SERVICE}" || true 50 | umount -f "/storage/${SERVICE}" || true 51 | if mountpoint -q "/storage/${SERVICE}"; then 52 | echo "failed to unmount: /storage/${SERVICE}" >&2 53 | exit 1 54 | fi 55 | fi 56 | } 57 | 58 | Install() { 59 | if ! which docker; then 60 | if ! which docker.io; then 61 | apt-get update && apt-get install -y docker.io 62 | fi 63 | ln -s "$(which docker.io)" /usr/local/bin/docker 64 | fi 65 | if mountpoint -q "/storage/${SERVICE}"; then 66 | echo "/storage/${SERVICE} is already mounted." >&2 67 | else 68 | if [ -f "/storage/${SERVICE}/image.dmg" ]; then 69 | echo "/storage/${SERVICE}/image.dmg already exists." >&2 70 | else 71 | mkdir -p "/storage/${SERVICE}" 72 | truncate --size="${DISK}" "/storage/${SERVICE}/image.dmg" 73 | yes | mkfs -t ext4 "/storage/${SERVICE}/image.dmg" 74 | fi 75 | Mount 76 | fi 77 | docker build --tag="${SERVICE}" . 78 | DOCKER_FLAGS=(--tty --interactive --rm) 79 | DockerRun /bin/bash /config/setup.sh 80 | } 81 | 82 | Uninstall() { 83 | Stop 84 | while true; do 85 | read -p "Do you really want to remove /storage/${SERVICE}? [yes/no] " yn 86 | if [ "${yn}" == 'yes' ]; then break; fi 87 | case "${yn}" in 88 | [Nn]*) exit;; 89 | *) echo "Please type 'Yes' or 'No'.";; 90 | esac 91 | done 92 | if mountpoint -q "/storage/${SERVICE}"; then 93 | umount -f "/storage/${SERVICE}" 94 | fi 95 | if [ -d "/storage/${SERVICE}" ]; then 96 | rm -rf "/storage/${SERVICE}" 97 | fi 98 | } 99 | 100 | command="$1" 101 | shift 102 | case "${command}" in 103 | 'start') Start "$@";; 104 | 'stop') Stop;; 105 | 'install') Install;; 106 | 'uninstall') Uninstall;; 107 | *) echo "no such command: ${command}" >&2;; 108 | esac 109 | --------------------------------------------------------------------------------