怎样用 Docker 部署 Seafile 服务器来托管你自己的文件同步和共享解决方案
Seafile 文件共享
![](/data/attachment/album/202204/13/141808f7fo7444ozv75z5s.jpg)


首先，什么是 Seafile ？


[Seafile](https://www.seafile.com/en/home/) 是一个自托管文件同步程序，采用客户端/服务器模式，即你有笔记本、手机等多个设备，能够连接到一个中心服务器。


不像类似 [Nextcloud 或 ownCloud](https://itsfoss.com/nextcloud-vs-owncloud/) 这些更流行的替代品一样，Seafile 试图遵循 “只做一件事，但是要做好” 的理念。同样，Seafile 没有内置额外的类似联系人或者日历聚合的功能。


相反，Seafile 只专注于文件同步、共享及与之相关的事情，仅此而已。但正因为如此，它最终做的非常好。


### 使用 Docker 和 NGINX 部署 Seafile 服务器



> 
> **高级教程**
> 
> 
> 我们的许多教程都是针对初学者的。这篇则不然，它是为那些经常鼓捣 DIY 项目和喜欢自托管的高级用户设计的。这个教程假定你可以熟练的使用命令行，而且你至少对我们将要使用的程序有一定的了解。
> 
> 
> 


虽然整个过程完全可以不使用 NGINX ，但是使用 NGINX 更加容易配置，而且在将来更加容易的自托管更多的服务。


如果你想完全使用 Docker 环境，你也可以 [在 Docker 内部设置 NGINX](https://linuxhandbook.com/nginx-reverse-proxy-docker/) ，但是它这会使事情变得更加复杂，并且不能够带来太多好处。同样，在本教程里也不会涉及这些。


#### 安装设置　NGINX


在这个教程中，我会使用 Ubuntu，因此会使用 `apt` 来安装软件包。如果你使用 Fedora 或者一些其他非 Debian 发行版，请使用你的发行版的 [包管理器](https://itsfoss.com/package-manager/)。


[NGINX](https://www.nginx.com/) 既是一个网页浏览器，又是一个代理服务器。它将起到 Seafile 服务器和互联网之间网络连接的作用，同时也使一些任务更容易处理。


要安装 NGINX ，使用以下命令：



```
sudo apt install nginx

```

如果你想使用 HTTPS（也就是浏览器中的小挂锁），你需要安装 [Certbot](https://certbot.eff.org/)：



```
sudo apt install certbot python3-certbot-nginx

```

下一步，你需要设置 NGINX 来连接我们之后将要设置的 Seafile 实例。


首先，运行以下命令：



```
sudo nano /etc/nginx/sites-available/seafile.conf

```

键入下方的文本到文件中：



```
server {
  server_name localhost;
  location / {
    proxy_pass http://localhost:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
  }
}

```

**重要**: 将 `server_name` 一行的 `localhost` 替换为你要访问你的服务器的地址（比如 `seafile.example.com` 或者 `192.168.0.0`）。不确定要输入什么吗？


* 如果你只是为了测试，使用 `localhost` 。这个设置将 **只允许你从你的电脑访问服务器** ，仅此而已。
* 如果你想通过你的本地 Wi-Fi 连接使用 Seafile（与你在同一 Wi-Fi 网络上），你应该键入 [你的计算机 IP 地址](https://itsfoss.com/check-ip-address-ubuntu/)。你也可以考虑 [设置一个静态 IP 地址](https://itsfoss.com/static-ip-ubuntu/)，尽管这不是必须的。
* 如果你有一个公网 IP 地址，你知道它指向你的系统，就使用它。
* 如果你有一个域名（比如 `example.com`、`example.org`）和公网 IP 地址，更改你的 DNS 设置，将域名指向你的系统的 IP 地址。这也需要将公网 IP 指向你的系统。


现在你需要复制配置文件到 NGINX 的查找目录中，然后重启 NGINX ：



```
sudo ln -s /etc/nginx/sites-available/seafile.conf /etc/nginx/sites-enabled/seafile.conf
sudo systemctl restart nginx

```

如果你要安装 Cerbot，你也需要运行以下命令来设置 HTTPS ：



```
sudo certbot

```

如果要重定向 HTTP 流量 到 HTTPS ，选择 `2` 。


现在可以来确认我们目前设置的一切都是否正常工作。如果你访问你的站点，你应该看到一个屏幕上写着 `502 Bad Gateway` 字样。


![](/data/attachment/album/202204/13/141813y33w8z333wlvvq33.png)


#### 安装 Docker 和 Docker Compose


现在要进入有趣的部分了!


首先，你需要安装 [Docker](https://www.docker.com/) 和 [Docker Compose](https://docs.docker.com/compose/) 。Docker Compose 需要利用 `docker-compose.yml` 文件，这将使管理多个 Docker [容器](https://www.docker.com/resources/what-container) 的 Seafile 需求变得更加容易。


Docker 和 Docker Compose 可以用以下的命令来安装：



```
sudo apt install docker.io docker-compose

```

检查 Docker 是否安装并运行，运行以下命令：



```
sudo docker run --rm hello-world

```

如果你完全安装成功，你应该在终端能看到这几行文字：


![](/data/attachment/album/202204/13/141814wq574ncenva0v4xx.png)


如果你想避免在 `docker` 命令的开始添加 `sudo` 的话，你可以运行以下的命令将你自己添加到 `docker` 组：



```
sudo groupadd docker
sudo usermod -aG docker $USER

```

这个教程的其余部分假定你已经运行了以上两个命令。如果你没有运行，在所有 `docker` 或 `docker-compose` 的命令都添加 `sudo` 。


#### 安装 Seafile 服务器


这部分比之前部分明显容易的多。你所需要做的是输入一些文本到文件，然后运行一些命令。


打开一个终端，然后创建一个 Seafile 服务器用来储存内容的目录，并进入目录中：



```
mkdir ~/seafile-server && cd ~/seafile-server

```

![](/data/attachment/album/202204/13/141814zscok1w1fxdt7111.png)


转到你创建的目录然后运行以下命令：



```
nano docker-compose.yml

```

下一步，在弹出的窗口中键入以下文本内容：



```
version: '2.0'
services:
  db:
    image: mariadb
    container_name: seafile-mysql
    environment:
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_LOG_CONSOLE=true
    volumes:
      - ./data/mariadb:/var/lib/mysql
    networks:
      - seafile-net

  memcached:
    image: memcached
    container_name: seafile-memcached
    entrypoint: memcached -m 256
    networks:
      - seafile-net
          
  seafile:
    image: seafileltd/seafile-mc
    container_name: seafile
    ports:
      - "8080:80"
    volumes:
      - ./data/app:/shared
    environment:
      - DB_HOST=db
      - DB_ROOT_PASSWD=password
      - TIME_ZONE=Etc/UTC
      - SEAFILE_ADMIN_EMAIL=me@example.com
      - SEAFILE_ADMIN_PASSWORD=password
      - SEAFILE_SERVER_LETSENCRYPT=false
      - SEAFILE_SERVER_HOSTNAME=docs.seafile.com
    depends_on:
      - db
      - memcached
    networks:
      - seafile-net

networks:
  seafile-net:

```

在保存文件之前，一些参数需要更改：


* `MYSQL_ROOT_PASSWORD`：更换强壮的密码，你不必记住它，所以不要尝试挑选简单的密码。如果你需要帮助生成一个，请使用 [密码生成器](https://itsfoss.com/password-generators-linux/) 。我建议使用 20 位字符长度并且避免使用任何的特殊字符（`!@#$%^&*` 等符号）。
* `DB_ROOT_PASSWD`：更改你为 `MYSQL_ROOT_PASSWORD` 设置的值 。
* `SEAFILE_ADMIN_EMAIL`：设置管理员帐户的电子邮件地址。
* `SEAFILE_ADMIN_PASSWORD`：设置管理员帐户密码。避免与`MYSQL_ROOT_PASSWORD` 或者 `DB_ROOT_PASSWD` 密码相同。
* `SEAFILE_SERVER_HOSTNAME`：在 NGINX 配置中设置 Seafile 的服务器主机名。


完成之后，你可以运行 `docker-compose` 整个运行起来：



```
docker-compose up -d

```

可能需要花一到两分钟，取决于你的网速，因为需要拉下几个 Seafile 需要运行的几个容器。


完成以后，还需要几分钟来完成。你也可以通过以下命令来检查运行状态：



```
docker logs seafile

```

当完成了，你将会看到如下输出：


![](/data/attachment/album/202204/13/141815vbh3rhdyb2hi4qdi.png)


下一步，你只需要在你的浏览器里键入你设置的 `SEAFILE_SERVER_HOSTNAME` 的地址，然后你应该看到登录屏幕的页面。


![](/data/attachment/album/202204/13/141815jkpi1tt1371oz054.jpg)


就这样！现在一切功能齐全，准备用客户端来使用。


#### 安装 Seafile 客户端


Seafile 移动客户端在 [Google Play](https://play.google.com/store/apps/details?id=com.seafile.seadroid2)、[F-Droid](https://f-droid.org/repository/browse/?fdid=com.seafile.seadroid2) 和 [苹果商店](https://itunes.apple.com/cn/app/seafile-pro/id639202512?l=en&mt=8) 都是可用的。Seafile 也有 Linux、Windows 和 Mac 桌面客户端可用，可在 [此处](https://www.seafile.com/en/download/) 找到。


通过 `seafile-gui` 软件包，可以在 Ubuntu 系统轻松获得 Seafile ：



```
sudo apt install seafile-gui

```

通过 `seafile-client` 软件包 Seafile 也包含在 Arch 用户的 AUR 包管理器中。


### 结语


请尽情探索客户端及其所能提供的一切。我将在未来的一篇文章中详细阐述 Seafile 客户端的所有功能。（敬请期待 ?）


总的来说，如果有什么错误，或者你有什么问题，请在下方评论 – 我会尽我所能回应。




---


via: <https://itsfoss.com/deploy-seafile-server-docker/>


作者：[Hunter Wittenborn](https://itsfoss.com/author/hunter/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[hwlife](https://github.com/hwlife) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
First off, what is Seafile?

[Seafile](https://www.seafile.com/en/home/) is a self-hosted file synchronization program that works with the server-client model, as in you have several devices like your laptop and phone that connect to a central server.

Unlike some more popular alternatives like [Nextcloud or ownCloud](https://itsfoss.com/nextcloud-vs-owncloud/), Seafile tries to follow the philosophy of “do one thing only, but do it well”. Likewise, Seafile doesn’t have extra goodies built in like Contacts or Calendar integration.

Seafile instead focuses solely on file syncing, sharing, and the things surrounding it, and that’s it. As a result of that though, it ends up doing so *extremely* well.

## Deploying Seafile Server with Docker and NGINX

Advanced tutorial

Most tutorials on It’s FOSS are focused on beginners. This one is not. It is intended for advanced users who tinker a lot with DIY projects and prefer to self-host.

This tutorial presumes that you are comfortable using the command line, and that you are at least decently knowledgeable with the programs we’ll be using.

While the whole process could be done without using NGINX at all, using NGINX will allow for an easier setup, as well as making it significantly easier to self-host more services in the future.

If you want to use a full-on Docker setup, you could set up [NGINX inside of Docker](https://linuxhandbook.com/nginx-reverse-proxy-docker/) as well, but it will only make things more complex and doesn’t add too much of a benefit, and likewise won’t be covered in this tutorial.

### Installing and Setting Up NGINX

*I will be using Ubuntu in this tutorial and will thus be using apt to install packages. If you use Fedora or some other non-Debian distribution, please use your distribution’s package manager.*

[NGINX](https://www.nginx.com/), as well as being a web server, is what’s known as a proxy. It will function as the connection between the Seafile server and the internet, whilst also making several tasks easier to deal with.

To install NGINX, use the following command:

`sudo apt install nginx`


If you want to use HTTPS (that little padlock in your browser), you will also need to install [Certbot](https://certbot.eff.org/):

`sudo apt install certbot python3-certbot-nginx`


Next, you need to configure NGINX to connect to the Seafile instance that we set up later.

First, run the following command:

`sudo nano /etc/nginx/sites-available/seafile.conf`


Enter the following text into the file:

```
server {
server_name localhost;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
```


**Important**: Replace **localhost** on the **server_name** line with the address you’ll be accessing your server from (i.e. **seafile.example.com** or **192.168.0.0**). Not sure what to put?

- If you are testing just for the sake of it, use localhost. This setup will
**only allow you to access the server from your computer**, and that’s it. - If you want to use Seafile across your local WiFi connection(any device on the same WiFi network as you), you should enter
[your computer’s IP address](https://itsfoss.com/check-ip-address-ubuntu/). You may also want to look into[setting a static IP address](https://itsfoss.com/static-ip-ubuntu/), though it isn’t necessary. - If you have a public IP address that you know points to your system, use that.
- If you have a domain name(i.e.
**example.com**,**example.org**)*and*a public IP address for your system, change your DNS settings to point the domain name to your system’s IP address. This will also require the public IP address to point to your system.

Now you need to copy the config file to the directory NGINX looks at for files, then restart NGINX:

```
sudo ln -s /etc/nginx/sites-available/seafile.conf /etc/nginx/sites-enabled/seafile.conf
sudo systemctl restart nginx
```


If you set up Certbot, you’ll also need to run the following to set up HTTPS:

`sudo certbot`


If asked to redirect HTTP traffic to HTTPS, choose **2**.

Now would be a good time to make sure everything we’ve set up so far is working. If you visit your site, you should get a screen that says something on the lines of `502 Bad Gateway`

.

![nginx bad gateway](https://itsfoss.com/content/images/wordpress/2021/04/nginx_bad_gateway.png)

### Install Docker and Docker Compose

Now to get into the fun stuff!

First things first, you need to have [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/) installed. Docker Compose is needed to utilize a docker-compose.yml file, which will make managing the various Docker [containers](https://www.docker.com/resources/what-container) Seafile needs easier.

Docker and Docker Compose can be installed with the following command:

`sudo apt install docker.io docker-compose`


To check if Docker is installed and running, run the following:

`sudo docker run --rm hello-world`


You should see something along the lines of this in your terminal if it completed successfully:

![seafile docker helloworld](https://itsfoss.com/content/images/wordpress/2021/04/seafile-docker-helloworld.png)

If you would like to avoid adding `sudo`

to the beginning of the `docker`

command, you can run the following commands to add yourself to the `docker`

group:

```
sudo groupadd docker
sudo usermod -aG docker $USER
```


The rest of this tutorial assumes you ran the above two commands. If you didn’t, add `sudo`

to all commands that start with `docker`

or `docker-compose`

.

### Installing Seafile Server

This part is significantly easier than the part before this. All you need to do is put some text into a file and run a few commands.

Open up a terminal. Then create a directory where you’d like the contents of the Seafile server to be stored and enter the directory:

`mkdir ~/seafile-server && cd ~/seafile-server`


![seafile dir](https://itsfoss.com/content/images/wordpress/2021/04/seafile-dir.png)

Go to the directory you created and run the following:

`nano docker-compose.yml`


Next, enter the text below into the window that pops up:

```
version: '2.0'
services:
db:
image: mariadb
container_name: seafile-mysql
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_LOG_CONSOLE=true
volumes:
- ./data/mariadb:/var/lib/mysql
networks:
- seafile-net
memcached:
image: memcached
container_name: seafile-memcached
entrypoint: memcached -m 256
networks:
- seafile-net
seafile:
image: seafileltd/seafile-mc
container_name: seafile
ports:
- "8080:80"
volumes:
- ./data/app:/shared
environment:
- DB_HOST=db
- DB_ROOT_PASSWD=password
- TIME_ZONE=Etc/UTC
-
```[[email protected]](/cdn-cgi/l/email-protection)
- SEAFILE_ADMIN_PASSWORD=password
- SEAFILE_SERVER_LETSENCRYPT=false
- SEAFILE_SERVER_HOSTNAME=docs.seafile.com
depends_on:
- db
- memcached
networks:
- seafile-net
networks:
seafile-net:


Before saving the file, a few things will need to be changed:

**MYSQL_ROOT_PASSWORD**: Change to a stronger password, you*don’t*need to remember this, so don’t try to pick anything easy. If you need help making one, use a[password generator](https://itsfoss.com/password-generators-linux/). I’d recommend 20 characters long and avoiding any special characters(all the**!@#$%^&***symbols).**DB_ROOT_PASSWD**: Change to the value you set for.**MYSQL_ROOT_PASSWORD**: Sets the email address for the admin account.**SEAFILE_ADMIN_EMAIL****SEAFILE_ADMIN_PASSWORD**: Sets the password for the admin account. Avoid making this the same as**MYSQL_ROOT_PASSWORD**or**DB_ROOT_PASSWD**.**SEAFILE_SERVER_HOSTNAME**: Set to the address you set in the NGINX configuration.

With that done, you can bring up the whole thing with `docker-compose`

:

`docker-compose up -d`


It might take a minute or two depending on your internet connection, as it has to pull down several containers that Seafile needs to run.

After it’s done, give it a few more minutes to finish up. You can also check the status of it by running the following:

`docker logs seafile`


When it’s done, you’ll see the following output:

![seafile running](https://itsfoss.com/content/images/wordpress/2021/04/seafile-running.png)

Next, just type the address you set for ** SEAFILE_SERVER_HOSTNAME** into your browser, and you should be at a login screen.

![seafile login](https://itsfoss.com/content/images/wordpress/2021/04/seafile-login-800x341.jpg)

And there you go! Everything’s now fully functional and ready to be used with the clients.

### Installing the Seafile Clients

Seafile on mobile is available on [Google Play](https://play.google.com/store/apps/details?id=com.seafile.seadroid2), [F-Droid](https://f-droid.org/repository/browse/?fdid=com.seafile.seadroid2), and on the [iOS App Store](https://itunes.apple.com/cn/app/seafile-pro/id639202512?l=en&mt=8). Seafile also has desktop clients available for Linux, Windows, and Mac, available [here](https://www.seafile.com/en/download/).

Seafile is readily available on Ubuntu systems via the `seafile-gui`

package:

`sudo apt install seafile-gui`


Seafile is also in the AUR for Arch users via the `seafile-client`

package.

## Closing Up

Feel free to explore the clients and all they have to offer. I’ll go into all of what the Seafile clients are capable of in a future article (stay tuned 😃).

If something’s not working right, or you just have a question in general, feel free to leave it in the comments below – I’ll try to respond whenever I can!