jotta / jotta-cli-issues

45 stars 1 forks source link

Feature request: Docker image for jotta-cli #22

Open iBrotNano opened 6 years ago

iBrotNano commented 6 years ago

jotta-cli release (0.3.4269):

Publish the app as a docker image

Running the service in a docker container to backup stuff might be usefull.

Here is a dockerfile to create such an image and a instruction how to use it. It maybe useful some day.

ARG ubuntu_version=16.04
FROM ubuntu:${ubuntu_version}

ARG jotta_cli_version=0.3.4269

LABEL maintainer="Your name and email"
LABEL org.label-schema.schema-version="1.0.0-rc.1"
LABEL org.label-schema.name="jottad"
LABEL org.label-schema.description="This image runs the Jottacloud deamon jottad."
LABEL org.label-schema.usage="/usr/doc/app-usage.txt"
LABEL org.label-schema.url="http://docs.jottacloud.com/jottacloud-command-line-tool"
LABEL org.label-schema.version="${jotta_cli_version}"

RUN apt-get clean \
    && apt-get update -y \
    && apt-get upgrade -y \
    && apt-get -y install wget apt-transport-https ca-certificates \
    && wget -O - https://repo.jotta.us/public.gpg | apt-key add - \
    && echo "deb https://repo.jotta.us/debian debian main" | tee /etc/apt/sources.list.d/jotta-cli.list \
    && apt-get update -y \
    && apt-get install jotta-cli=${jotta_cli_version} -y \
    && apt-get autoremove -y \
    && apt-get clean \
    && rm -rf /var/lib/lists/*

EXPOSE 53

ENTRYPOINT [ "jottad","stdoutlog" ]

Here is how to use it:

How can i create the image?

Install Docker

First remove all old installations of Docker if there are any.

sudo apt-get remove docker-engine docker.io

The Docker package is renamed into docker-ce.

Then update the package cache.

sudo apt-get update

You will need some dependencies to install Docker.

sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

apt must know the gpg key for the Docker repository.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Ensure that always the stable version will be installed.

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Update the package index again and install docker-ce.

sudo apt-get update
sudo apt-get install docker-ce

You will need an additional component to compose Docker images.

sudo apt-get install docker-compose

Create the image

The image could be build now by changing the directory to the one the dockerfile is located. The dockerfile contains to ARG wich defines the versions of Ubuntu and jotta-cli. You can change them by passing arguments to docker build.

docker build -t jotta-cli:0.3.4183 --build-arg ubuntu_version=18.04 --build-arg jotta_cli_version=0.3.4183 .

If you don't pass any arguments the defaults in the dockerfile will be used.

docker build -t jotta-cli:latest .

How can i use the image?

Prepare the container

First of all you don't want to configure jotta-cli every time you create a jotta-cli-container when you want to update jotta-cli. So you need to create a volume to persist the configuration.

docker volume create jotta-cli

The configuration files will be stored in the volume. On Linux the path is /var/lib/docker/volumes/jotta-cli/_data.

Now you can create the container.

docker run -d --name jotta-cli --mount source=jotta-cli,target=/root/.jottad --mount type=bind,source=/,target=/sync,readonly jotta-cli:latest

You will notice that two mounts are made. The first mounts the created volume to /root/.jottad where the configuration is stored. The second mounts the hosts / into the containers /sync/. This way jottad could access the hosts filesystem to backup files. The hosts filesystem is mounted as readonly so that the container could not change anything on your host.

Keep attention to mount / only in a subfolder in the container!

Login into Jottacloud

To enter you Jottacloud credentials you must open a bash on the container. The output of jotta-cli login could not be displayed with Docker's exec command.

docker exec -it jotta-cli /bin/bash

In the container's bash log into your Jottacloud account.

jotta-cli login

Now you can exit the container with exit. Every other configuration could be made with exec.

The most important command it to add a path to backup.

docker exec jotta-cli jotta-cli add /sync/var/lib/docker/volumes

This adds the path where Docker stores volumes to the observed folders. This way the container saves it's own configuration in the cloud.

torarnv commented 6 years ago

Nice! Does this actually work, despite the filsystem limitations described in https://github.com/jotta/jotta-cli-issues/issues/7 ?

iBrotNano commented 6 years ago

Sorry. I'm not sure about the NFS filesystem. I had a similar error first when i tried to backup data directly from within a docker container.

Unsupported filesystem [OVERLAYFS_SUPER_MAGIC]

It's the filesystem docker uses internally. By mounting the hosts filesystem with --mount type=bind into the container i could work around this error message. Maybe the error is caused by the way NFS is mounted into the VM from #7 and not by NFS itself.

rkarlsba commented 6 years ago

It's the same limits - they have made a whitelist of supported filesystems for some reason, probably to avoid someone doing something as cruel as to use space for multiple machines. That whitelisting filesystems thing doesn't make sense in these days of everything-virtual.

hlov commented 6 years ago

@torarnv Running jotta-cli v0.4 in a docker container with mounted system volumes works perfectly fine :)

iBrotNano commented 6 years ago

I am using it for a while now and it seems to work quit good. I use it in conjunction with a script executed by a crontjob to backup some folder.

#!/bin/bash

backupFolderPath=/backups
# Cleanup of the backup folder by removing it completly.
rm -r ${backupFolderPath}
domain=example.com

# Creating the backup folder.
mkdir $backupFolderPath

# Creating a unique filename with a timestamp.
timestamp=$(date +"%F-%H%M%S")
backupFileName=${timestamp}-backup-${domain}.zip
destination=$backupFolderPath/$backupFileName

# Zipping the backup data.
zip -r ${destination} /home /var/lib/docker/volumes /etc

# Uploading the backup zip to the cloud.
docker exec jotta-cli jotta-cli archive /sync/${destination} --nogui

It zips some folders and uploads it to Jottacloud. It is not the most powerful backup solution but it is something.

Antwelm commented 3 years ago

Seems like someone elaborated on this: https://hub.docker.com/r/jaco1960/jottacloud

Haven't tried it though, but I will, if I can get my head around it..