Mysql Docker在尝试连接时出错

Mysql Docker在尝试连接时出错,mysql,docker,mariadb,mysql-error-2003,Mysql,Docker,Mariadb,Mysql Error 2003,我有两个我正在尝试运行的mariadb实例(为了向后兼容,我需要一个)。这是他们两人的docker-compose.yml: db: container_name: db image: mariadb:latest ports: - "3306:3306" networks: devel: ipv4_address: 172.19.0.105 volumes: - "${

我有两个我正在尝试运行的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\u DIR}
是一个变量,它是启动docker容器的命令的一部分,因此应该在那里并且是正确的,以防有人怀疑

更新: 下面是我的db2 docker日志:

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

运行
docker ps
如果
db2
正在运行,则运行
docker日志db2
以查看logs@Saeed容器正在运行。我把日志贴在了我的问题上,这就成功了。非常感谢。