Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Deploy Seafile Server Through Docker

Recommended Server Minimums

  • 2 Cores
  • 2GB or more for memory.
  • 1GB for swap if possible.

If you have 4GB+ of memory, you probably don't need the swap.

Steps

Firstly install docker and install install docker compose.

Create Docker Compose File

Copy and paste the following docker-compose.yml file to your server, (this is what the source was at the time of writing this tutorial)/

version: '2.0'
services:
  db:
    image: mariadb:10.5
    container_name: seafile-mysql
    environment:
      - MYSQL_ROOT_PASSWORD=db_dev  # Requested, set the root's password of MySQL service.
      - MYSQL_LOG_CONSOLE=true
    volumes:
      - /opt/seafile-mysql/db:/var/lib/mysql  # Requested, specifies the path to MySQL data persistent store.
    networks:
      - seafile-net

  memcached:
    image: memcached:1.5.6
    container_name: seafile-memcached
    entrypoint: memcached -m 256
    networks:
      - seafile-net

  seafile:
    image: seafileltd/seafile-mc:latest
    container_name: seafile
    ports:
      - "80:80"
#     - "443:443"  # If https is enabled, cancel the comment.
    volumes:
      - /opt/seafile-data:/shared   # Requested, specifies the path to Seafile data persistent store.
    environment:
      - DB_HOST=db
      - DB_ROOT_PASSWD=db_dev  # Requested, the value shuold be root's password of MySQL service.
      - TIME_ZONE=Etc/UTC  # Optional, default is UTC. Should be uncomment and set to your local time zone.
      - SEAFILE_ADMIN_EMAIL=me@example.com # Specifies Seafile admin user, default is 'me@example.com'.
      - SEAFILE_ADMIN_PASSWORD=asecret     # Specifies Seafile admin password, default is 'asecret'.
      - SEAFILE_SERVER_LETSENCRYPT=false   # Whether to use https or not.
      - SEAFILE_SERVER_HOSTNAME=docs.seafile.com # Specifies your host name if https is enabled.
    depends_on:
      - db
      - memcached
    networks:
      - seafile-net

networks:
  seafile-net:

Change Settings

Now copy/paste the script below, before filling in the variables at the top of it and then executing it.

When it runs, it will automatically set a strong random password for the seafile database, and configure the admin username/password, as well as the hostname of the server. Alternatively, you can just edit the docker-compose.yml file directly.

#!/bin/bash

# Fill in the settings below. I have pre-populated with some example values.
SEAFILE_ADMIN_EMAIL="admin@programster.org"
SEAFILE_ADMIN_PASSWORD="thisIsMyAdminLogingPassword"
SEAFILE_SERVER_HOSTNAME="seafile.programster.org"


# Generate a random password for mysql database
RANDOM_PASSWORD=`head /dev/urandom | tr -dc A-Za-z0-9 | head -c16`


# set password for mysql service
SEARCH="      - MYSQL_ROOT_PASSWORD=db_dev"
REPLACE="      - MYSQL_ROOT_PASSWORD=$RANDOM_PASSWORD"
FILEPATH="docker-compose.yml"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH


# tell seafile to use the mysql password
SEARCH="      - DB_ROOT_PASSWD=db_dev"
REPLACE="      - DB_ROOT_PASSWD=$RANDOM_PASSWORD"
FILEPATH="docker-compose.yml"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH


# Set the admin password
SEARCH="      - SEAFILE_ADMIN_PASSWORD=asecret"
REPLACE="      - SEAFILE_ADMIN_PASSWORD=$SEAFILE_ADMIN_PASSWORD"
FILEPATH="docker-compose.yml"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH


# Set the admin email
SEARCH="      - SEAFILE_ADMIN_EMAIL=me@example.com"
REPLACE="      - SEAFILE_ADMIN_EMAIL=$SEAFILE_ADMIN_EMAIL"
FILEPATH="docker-compose.yml"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH


# Set the hostname
SEARCH="      - SEAFILE_SERVER_HOSTNAME=docs.seafile.com"
REPLACE="      - SEAFILE_SERVER_HOSTNAME=$SEAFILE_SERVER_HOSTNAME"
FILEPATH="docker-compose.yml"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH

A Note On Volumes

By default, the docker-compose file will store your database data at: /opt/seafile-mysql/db and your seafile application data at: /opt/seafile-data. If you are using a separate disk-drive for all of your data, you may wish to review/change these values.

If you don't understand anything I just said, you probably want to just continue as-is.

A Note On Versions

By default, the docker-compose file specifies to use the image: seafileltd/seafile-mc:latest which will always use the latest image. To prevent accidents happening later, I would advise manually changing :latest to the latest current version number in the dockerhub registry. E.g. at the time of writing this tutorial, it is 8.0.3 so I have manually set it to that. This way if I perform a docker pull later, I won't accidentally pulll down 9.x in the future and risk issues. However, 8.03 might not be around when you read this, so tutorial needs to keep it set at :latest in the documentation.

Deploy!

Run the following command to deploy

docker-compose up

If you need to deploy "silently" and not see the output and tie-up your terminal, then you can use:

docker-compose up -d

References

Last updated: 22nd February 2021
First published: 21st February 2021