Seafile (with MariaDB)

Introduction

Seafile is an open-source, cross-platform file-hosting software system. Files are stored on a central server and can be synchronized with personal computers and mobile devices through apps. Files on the Seafile server can also be accessed directly via the server's web interface. Seafile's functionality is similar to other popular file hosting services such as Dropbox and Google Drive.

The Docker Compose File

---
version: "3.8"

services:
  mariadb:
    image: mariadb:latest
    container_name: mariadb
    hostname: mariadb
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    env_file:
      - .env
    environment:
      - TZ=${TZ}
      - MARIADB_AUTO_UPGRADE=${MARIADB_AUTO_UPGRADE}
      - MYSQL_LOG_CONSOLE=${MYSQL_LOG_CONSOLE}
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
    healthcheck:
      test: "healthcheck.sh --connect"
      start_period: 30s
      interval: 10s
      timeout: 10s
      retries: 5
    volumes:
      - /opt/seafile/database:/var/lib/mysql
      - /etc/localtime:/etc/localtime:ro
    networks:
      - seafile_net
    labels:
      - com.centurylinklabs.watchtower.enable=true

  memcached:
    image: memcached:latest
    container_name: memcached
    hostname: memcached
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    entrypoint: memcached -m 256
    networks:
      - seafile_net
    labels:
      - com.centurylinklabs.watchtower.enable=true

  seafile:
    image: seafileltd/seafile-mc:latest
    container_name: seafile
    hostname: seafile
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    env_file:
      - .env
    environment:
      - TZ=${TZ}
      - DB_HOST=${DB_HOST}
      - DB_ROOT_PASSWD=${DB_ROOT_PASSWD}
      - SEAFILE_ADMIN_EMAIL=${SEAFILE_ADMIN_EMAIL}
      - SEAFILE_ADMIN_PASSWORD=${SEAFILE_ADMIN_PASSWORD}
      - SEAFILE_SERVER_LETSENCRYPT=${SEAFILE_SERVER_LETSENCRYPT}
      - SEAFILE_SERVER_HOSTNAME=${SEAFILE_SERVER_HOSTNAME}
    ports:
      - 80:80
    volumes:
      - /opt/seafile/config:/shared
    depends_on:
      mariadb:
        condition: service_healthy
      memcached:
        condition: service_started
    networks:
      - seafile_net
    labels:
      - com.centurylinklabs.watchtower.enable=true

networks:
  seafile_net:
    external: true

docker-compose.yml

The Docker Environment Variables File

TZ=Europe/Stockholm
MARIADB_AUTO_UPGRADE=1
MYSQL_LOG_CONSOLE=true
MYSQL_ROOT_PASSWORD=secretpassword
DB_HOST=mariadb
DB_ROOT_PASSWD=secretpassword
[email protected]
SEAFILE_ADMIN_PASSWORD=secretpassword
SEAFILE_SERVER_LETSENCRYPT=false
SEAFILE_SERVER_HOSTNAME=seafile.mydomain.com

.env

This Docker Compose file defines three services, the app is named “seafile”, the database is called “mariadb” and the memory object caching system is called "memcached". The services are built from the latest Docker images. The container names ares set to “seafile”, “mariadb” and “memcached” as well.

The “restart” section ensures that the container will always be restarted if it exits (unless manually stopped). This is useful for ensuring that the services are always available, especially if they crash or are shut down unexpectedly.

The “security_opt” section prevents your container processes from gaining additional privileges. This is an important security consideration.

The “ports” section for seafile maps port 80 on the host machine to port 80 in the container. This allows us to access the seafile web interface from our local machine. The mariadb database maps to its standard port of 3306.

The “volumes” section maps the “/shared” and “/var/lib/mysql” directories inside the containers to local directories on the host machine. This allows us to persist data across container restarts. seafile stores all its configuration data in its own directory and mariadb stores its database in its own directory, so it’s important to keep it intact.

The "labels" section allows the Watchtower service to keep this container update automatically.

Running Seafile with Docker Compose

To run Seafile with Docker Compose, first, make sure you have Docker and Docker Compose installed on your machine. Then, create a new directory for your project and save the above Docker Compose file as “docker-compose.yml” in that directory along with the environment variables as “.env”.

Next, run the following command from the same directory:

docker compose up -d

This command will start the Seafile container in the background and detach from it. You can then access the Seafile web interface by going to http://localhost in your web browser.

Conclusion

In this article, we explored how to set up and run the Seafile software using Docker Compose. We looked at the different sections of the Docker Compose file and explained how they work together to create a functional Seafile service. By running Seafile with Docker Compose, you can easily deploy and manage the tool on your own server, without having to worry about dependencies or configuration.


Seafile - Open Source File Sync and Share Software
Seafile is an open source, self-hosted file sync and share solution with high performance and reliability. Sync, access, and collaborate on files on your own server or private cloud.