"Connection refused" to mysql in docker

I restarted my RPi today and afterwards Seafile broke down:

seafile            | 2024-03-12T14:54:56.822688658Z waiting for mysql server to be ready: %s (2003, "Can't connect to MySQL server on 'seafile_db' ([Errno 111] Connection refused)")
seafile            | 2024-03-12T14:54:56.822790490Z waiting for mysql server to be ready: %s (2003, "Can't connect to MySQL server on 'seafile_db' ([Errno 111] Connection refused)")
seafile            | 2024-03-12T14:54:56.822808176Z waiting for mysql server to be ready: %s (2003, "Can't connect to MySQL server on 'seafile_db' ([Errno 111] Connection refused)")
seafile            | 2024-03-12T14:54:56.822824157Z waiting for mysql server to be ready: %s (2003, "Can't connect to MySQL server on 'seafile_db' ([Errno 111] Connection refused)")
seafile            | 2024-03-12T14:54:56.822839824Z waiting for mysql server to be ready: %s (2003, "Can't connect to MySQL server on 'seafile_db' ([Errno 111] Connection refused)")

From mysql service I see connection attempts:

seafile-mysql      | 2024-03-12T14:54:56.816885319Z 2024-03-12 14:54:56 3 [Warning] Aborted connection 3 to db: 'unconnected' user: 'seafile' host: '' (Got an error reading communication packets)

I checked the username/password (from seafile/conf/ccnet.conf) and I can connect to the mysql instance just fine (either locally from mysql container or from the bash in seafile container):

$ docker compose exec -it seafile /bin/bash
root@c6e222dbffef:/opt/seafile# mysql -hseafile-mysql -useafile -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 28
Server version: 5.5.5-10.11.7-MariaDB-1:10.11.7+maria~ubu2204 mariadb.org binary distribution

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
| Database           |
| ccnet_db           |
| information_schema |
| seafile_db         |
| seahub_db          |
4 rows in set (0.00 sec)

Grants looks ok:

MariaDB [(none)]> select * from information_schema.user_privileges
    -> ;
| GRANTEE                   | TABLE_CATALOG | PRIVILEGE_TYPE           | IS_GRANTABLE |
| 'seafile'@'%.%.%.%'       | def           | USAGE                    | NO           |

$ docker compose ps
NAME                IMAGE                          COMMAND                  SERVICE      CREATED          STATUS                    PORTS
seafile             seafileltd/seafile-mc:latest   "/sbin/my_init -- /s…"   seafile      14 minutes ago   Up 14 minutes             80/tcp
seafile-memcached   memcached:1.6                  "memcached -m 256"       memcached    57 minutes ago   Up 20 minutes
seafile-mysql       mariadb:10.11                  "docker-entrypoint.s…"   seafile_db   14 minutes ago   Up 14 minutes (healthy)

Any hint what can be wrong?

(ref: "Connection refused" to mysql in docker · Issue #2747 · haiwen/seafile · GitHub)

I ran into the exact same issue this afternoon. I was at a loss how to fix it, because I have set up seafile already a number times in different containers and did not have this problem.

Have you found any solution?

There was seemingly related thread: Access Denied by database no matter what. · haiwen/seafile · Discussion #2729 · GitHub

I’m somewhat reluctant to downgrade (not sure if supported and what would be the implications) by switching image: seafileltd/seafile-mc:latest to previous version…

Seems like you might be dealing with something similar to what I did. If either Seafile (or seadoc or MySQL, etc) is running on docker, and the other service is running on the host machine, they will be on different networks. A docker container is somewhat like a different computer running on the same LAN. You can configure multiple docker containers to run on the same network, but I don’t think you can configure them to run on the same network as the host.

So a docker program won’t be able to connect to MySQL running on localhost because it’s running on a different network. You have to edit your my.cnf file (or 50-server.cnf if you’re using Mariadb) and set the bind address to I tried adding multiple bind addresses, including (localhost) and the docker IP addresses, but Mariadb wouldn’t start back up, so I just used, which lets any IP address connect. I also had to open the MySQL port on my ufw firewall.

My error was exactly the same (Errno 111), so hopefully this works for you too. This really should be documented in the server manual, because it took me forever to figure it out.

Hi and thank you for the reply.

Unfortunately in my case I’m using docker compose and all elements are handled by it (and they use same network). What’s more - this exact setup was working just fine but I think seafile got updated during my system update (I’m using “latest” image tag) and something changed.

As for the connectivity - I entered containers of seafile (which reports the error), I installed mysql client and connected just fine to the database!

It looks like seafile tries something funny it I can’t put my finger on it :frowning:

If you just updated your system, I’d make sure that all of the python packages are installed. Another thing I ran into was that Seafile ran fine on Ubuntu 20.04 with python 3.12. After I updated to Ubuntu 22.04, Seahub would no longer start with python 3.12, but it would with python 3.10. Although now it seems to work with both versions… I would imagine that the docker containers use their own python libraries, so this probably isn’t the problem.

You might check to see if you can log access attempts to the MySQL database to see if you can narrow down what’s causing the problem.

Hmm… python packages shouldn’t be an issue as I do everything inside docker (so python is within seafile images provided by devs) but I’ll try to see mysql logs - indeed maybe there should be more info

Is this ok? I used to create the user this way: ‘dbuser’@‘%’ for something else if I remember correctly.

This may be related to a closed port issue. Or no connectivity.
Can you check the docker compose configuration?

Also eg. for me - I had serious issues with docker and resolving the domain names, but maybe I’m just a noob… Every time I install the freaking docker it screws my server, so now I’m just virtualizing that shit with Nextcloud AIO docker solution (yea, no more Seafile for me, thanks - issues with v11 upgrade got me extremely frustrated).

AFAIR it should be, but should only allow connectivity from IPs and not hostnames. I’ll try adjusting grants though.

compose is quite regular:

$ cat docker-compose.yml
#version: '2.0'
version: '3.3'
    image: mariadb:10.11
    container_name: seafile-mysql
    restart: unless-stopped
      - MYSQL_ROOT_PASSWORD=[pass]
      - MYSQL_LOG_CONSOLE=true
        test: ["CMD", "mysqladmin" ,"ping", "-h", "seafile-mysql"]
        timeout: 20s
        retries: 10
      - ../_data/seafile/db:/var/lib/mysql
      - seafile-net

    image: memcached:1.6
    container_name: seafile-memcached
    restart: unless-stopped
    entrypoint: memcached -m 256
      - seafile-net

    #image: seafileltd/seafile-mc:latest
    image: seafileltd/seafile-mc:11.0.5
    container_name: seafile
    restart: unless-stopped
      - ../_data/seafile/seafile-data:/shared
      - DB_HOST=seafile_db
      - DB_ROOT_PASSWD=[pass]
      - TIME_ZONE=Etc/UTC
      - seafile_db
      - memcached
      - seafile-net
      - scoobydooex

  # communication to web and clients
    name: scoobydoo
    external: true
    driver: bridge
    internal: true

I can attach to bash on seafile container and connect just fine using $ mysql to the seafile_db

Hey, did you find a way to fix this? I’m having the exact same problem. Seadrive seems to be able to connect to the seafile server, but the webserver doesn’t seem to be able to start, and I’m getting the same error 111:

Starting seahub at port 8000 …
Error:Seahub failed to start.
Please try to run “./seahub.sh start” again
Traceback (most recent call last):
File “/scripts/start.py”, line 95, in
waiting for mysql server to be ready: %s (2003, “Can’t connect to MySQL server on ‘db’ ([Errno 111] Connection refused)”)
File “/scripts/start.py”, line 81, in main
call(‘{} start’.format(get_script(‘seahub.sh’)))
File “/scripts/utils.py”, line 70, in call

I just restored this as a VM in proxmox from a pbs backup from a day ago, when everything was working perfectly fine.

@murtaza-nasir Actualy I don’t remember what fixed it in the issue. I think I was downgrading/upgrading the image version while debugging it that at one point it started…

to be honest, between this issue and seafile android up not working correctly (issues with photo update) I just gave up on seafile and move to syncthing - it works more reliably and I’m sure my photos are backed up…

While seafile works I keep to backup stuff from my laptop (backup-of-a-backup) and sometimes share stuff but next time it breaks or whatnot it’ll be out of the window…