iPlay / iTech / Linux · 2022年4月5日

升级docker版seafile的心得

警告

禁止使用docekr-compose down !

禁止使用docekr-compose down !

禁止使用docekr-compose down !

好几次,一旦使用这个命令,seafile的所有资料都会被清空!!!

一切从头再来

昨晚按照seafile官方的指导文件打算把docker版的seafile从7.1升级到8.0版本。官方指导文件是这么写的:

只需下载新映像,停止旧的 Docker 容器,将 docker-compose.yml 中的 Seafile 映像版本修改为新版本,然后从 docker-compose 开始。

我用docker pull seafileltd/seafile-mc:latest 拉取了最新的镜像,用docker-compose restart 重启了一下docker-compose.yml。但发现容器使用的镜像还是旧的镜像,难道用在docker-compose.yml文件里把image: seafileltd/seafile-mc:latest改为image: seafileltd/seafile-mc:8.0.4 ?(我猜的,等以后再验证吧)一怒之下,我用了docker-compose down后,看着磁盘占用大小从11%慢慢降到了1%,我才意识到追悔莫及啊。整个世界都清凉了!重新docker-compose up -d 结果发现只成功启动了seafile-memcached ,其他两个容器都没拉起来,查看docker logs 容器ID 日志才发现出现了这个错误。

[root@pricloud seafile]# docker logs seafile-mysql
2022-04-05 00:28:09+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.5.13+maria~focal started.
chown: changing ownership of '/var/lib/mysql/': Permission denied

已经是深夜了,找不到头绪,睡觉了。

我又回来了

很明显是docker-compose 容器中的root没有宿主机的root权限。在昨天折腾onlyoffice的时候也出现了这个Permission denied的错误,后来使用了--privileged=true 后容器就开起来了。但是在docker-compose的yml文件中如何使用呢,早上起来Google了一下,找到答案了。在docker-compose.yml文件中使用 privileged: true 即可。在有需要挂载-v 的容器中加入即可。示例如下:

version: '2.0'
services:
  db:
    image: mariadb:10.5
    container_name: seafile-mysql
    privileged: true
    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
    privileged: true
    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=Asia/Shanghai # 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 use letsencrypt to generate cert.
      - SEAFILE_SERVER_HOSTNAME=seafile.example.com # Specifies your host name.
    depends_on:
      - db
      - memcached
    networks:
      - seafile-net

networks:
  seafile-net:

升级seafile版本的正确方法

拉取最新版本的镜像

docker pull seafileltd/seafile-mc:latest
[root@pricloud seafile]# docker images
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
docker.io/seafileltd/seafile-mc   latest              fc5c2df1e1bb        6 weeks ago         1.02 GB
docker.io/mariadb                 10.5                9a0e59bdf6f0        4 months ago        408 MB
docker.io/seafileltd/seafile-mc   <none>              5653eeeb2d86        7 months ago        931 MB
docker.io/memcached               1.5.6               855fdf342eda        4 years ago         58.6 MB

停止旧版本的seafile镜像

docker container stop seafile

启用新版本,注意不是使用docker-compose restart

docker-compose up -d
[root@pricloud seafile]# docker-compose up -d
seafile-mysql is up-to-date
seafile-memcached is up-to-date
Recreating seafile ... done

查看docker 容器运行状态

[root@pricloud seafile]# docker ps
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                                        NAMES
38c60dbcab88        seafileltd/seafile-mc:latest   "/sbin/my_init -- ..."   8 seconds ago       Up 7 seconds        0.0.0.0:443->443/tcp, 0.0.0.0:8088->80/tcp   seafile
b1843fbb2c7a        mariadb:10.5                   "docker-entrypoint..."   About an hour ago   Up 56 seconds       3306/tcp                                     seafile-mysql
398a85a5af7f        memcached:1.5.6                "memcached -m 256"       About an hour ago   Up 57 seconds       11211/tcp                                    seafile-memcached