Docker 尝试连接 mariadb 111 错误

Docker mariadb 111 error trying to connect

我有两个我正在尝试的 mariadb 实例 运行(我需要一个用于向后兼容)。这是他们两个的 docker-compose.yml:

  db:
    container_name: db
    image: mariadb:latest
    ports:
      - "3306:3306"
    networks:
      devel:
        ipv4_address: 172.19.0.105
    volumes:
      - "${DATA_DIR}/mariadb:/var/lib/mysql"
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: 1
  db2:
    container_name: db2
    image: mariadb:10.2.37
    ports:
      - "3307:3306"
    networks:
      devel:
        ipv4_address: 172.19.0.106
    volumes:
      - "${DATA_DIR}/mariadb2:/var/lib/mysql"
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: 1

我可以连接到第一个,标记为 db 的,没问题,但第二个出现以下错误:

ERROR 2003 (HY000): Can't connect to MySQL server on '172.19.0.106' (111)

这是我试图运行访问它的命令:

mysql --user=root --host=172.19.0.106 --port=3307

我不确定为什么无法连接。信息看起来是正确的,但它不起作用,所以我不知道我做错了什么。

此外,${DATA_DIR} 是一个变量,它是启动 docker 容器的命令的一部分,所以它应该存在并且是正确的,以防有人想知道。

更新: 这是我的 docker db2 日志:

2021-03-16 21:53:54+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.2.37+maria~bionic started.
2021-03-16 21:53:54+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-03-16 21:53:54+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.2.37+maria~bionic started.
2021-03-16 21:53:55 140078898230976 [Note] mysqld (mysqld 10.2.37-MariaDB-1:10.2.37+maria~bionic) starting as process 1 ...
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Uses event mutexes
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Using Linux native AIO
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Number of pools: 1
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Using SSE2 crc32 instructions
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Completed initialization of buffer pool
2021-03-16 21:53:55 140078171240192 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-03-16 21:53:55 140078898230976 [Warning] InnoDB: Failed to set O_DIRECT on file./ibdata1;OPEN: Invalid argument, ccontinuing anyway. O_DIRECT is known to result in 'Invalid argument' on Linux on tmpfs, see MySQL Bug#26662.
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Setting log file ./ib_logfile101 size to 50331648 bytes
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Setting log file ./ib_logfile1 size to 50331648 bytes
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: New log files created, LSN=8280100
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Highest supported file format is Barracuda.
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: 128 out of 128 rollback segments are active.
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Waiting for purge to start
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: 5.7.33 started; log sequence number 8280588
2021-03-16 21:53:55 140077934044928 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2021-03-16 21:53:55 140078898230976 [Note] Plugin 'FEEDBACK' is disabled.
2021-03-16 21:53:55 140078898230976 [Note] Server socket created on IP: '::'.
2021-03-16 21:53:55 140078898230976 [Warning] 'proxies_priv' entry '@% root@98c35665786d' ignored in --skip-name-resolve mode.
2021-03-16 21:53:55 140078898230976 [Note] Reading of all Master_info entries succeeded
2021-03-16 21:53:55 140078898230976 [Note] Added new Master_info '' to hash table
2021-03-16 21:53:55 140078898230976 [Note] mysqld: ready for connections.
Version: '10.2.37-MariaDB-1:10.2.37+maria~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
2021-03-16 21:53:56 140077934044928 [Note] InnoDB: Buffer pool(s) load completed at 210316 21:53:56

使用 localhost (127.0.0.1) 作为主机而不是 dock 容器的 IP 地址,因为你有一个绑定端口。默认情况下,mysql 客户端使用本地主机上的 sock 文件而不是 tcp 协议。尝试以下命令:

mysql --user=root --host=127.0.0.1 --port=3307 --protocol=tcp