GreatSQL社区

搜索

[已解决] 容器化安装greatsql,映射3306端口报错

114 6 2024-3-3 22:50
你好,


根据 文档运行greatsql 容器没问题,但3306端口未映射到宿主机上,应用连接不到容器内部 3306端口,我把3306端口通过 docker run映射出来,启动报错:


docker -v
Docker version 19.03.9, build 9d988398e7


docker pull greatsql
docker run -d --name greatsql -p 3306:3306 --hostname=greatsql -e MYSQL_ALLOW_EMPTY_PASSWORD=1 greatsql/greatsql


181c3218d2116b705f1233c51c1e8e9e8e77c3e1ff0cf3b82c47ae935625c250

docker: Error response from daemon: driver failed programming external connectivity on endpoint greatsql (24c4bbd2cffa148962efec16d0c8d351a4d720812cb85ee9e686cda87ce9f538):  (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 3306 -j DNAT --to-destination 172.17.0.2:3306 ! -i docker0: iptables: No chain/target/match by that name.
(exit status 1)).


全部回复(6)
yejr 2024-3-4 09:19:45
宿主机环境中确认没有其他服务进程已经抢先监听3306端口了吗,请再次确认下
szhjb88 2024-3-4 09:48:18
yejr 发表于 2024-3-4 09:19
宿主机环境中确认没有其他服务进程已经抢先监听3306端口了吗,请再次确认下 ...

ss -nlt
State                  Recv-Q                 Send-Q                                 Local Addressort                                  Peer Addressort                Process               
LISTEN                 0                      128                                          0.0.0.0:22                                         0.0.0.0:*                                          
LISTEN                 0                      5                                            0.0.0.0:8601                                       0.0.0.0:*                                          
LISTEN                 0                      511                                          0.0.0.0:443                                        0.0.0.0:*                                          
LISTEN                 0                      5                                            0.0.0.0:19200                                      0.0.0.0:*                                          
LISTEN                 0                      511                                          0.0.0.0:810                                        0.0.0.0:*                                          
LISTEN                 0                      1024                                         0.0.0.0:5355                                       0.0.0.0:*                                          
LISTEN                 0                      511                                          0.0.0.0:80                                         0.0.0.0:*                                          
LISTEN                 0                      1024                                               *:7000                                             *:*                                          
LISTEN                 0                      1024                                            [::]:5355                                          [::]:*                                          
LISTEN                 0                      1024                                               *:18700                                            *:*            
szhjb88 2024-3-4 09:49:23
szhjb88 发表于 2024-3-4 09:48
ss -nlt
State                  Recv-Q                 Send-Q                                 Loca ...

docker run -d --name greatsql -p 3306:3306 --hostname=greatsql -e MYSQL_ALLOW_EMPTY_PASSWORD=1 greatsql/greatsql
6226686acbb03c91b81232b30026fdb11c752c5371f6a47add1429175c3f49ce
docker: Error response from daemon: driver failed programming external connectivity on endpoint greatsql (ab93ee1974324e16d85c9e9897e023360adaaa7a42a0626899ba2c7e102f2375):  (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 3306 -j DNAT --to-destination 172.17.0.2:3306 ! -i docker0: iptables: No chain/target/match by that name.
(exit status 1)).
szhjb88 2024-3-4 09:53:56
szhjb88 发表于 2024-3-4 09:49
docker run -d --name greatsql -p 3306:3306 --hostname=greatsql -e MYSQL_ALLOW_EMPTY_PASSWORD=1 gr ...

你好,

检查宿主机的3306端口没有被占用,如果去掉端口映射,就正常。
yejr 2024-3-4 11:24:18
szhjb88 发表于 2024-3-4 09:53
你好,

检查宿主机的3306端口没有被占用,如果去掉端口映射,就正常。

下面是我的操作过程,是正常的
  1. [root@db170 ~]# ss -lntp
  2. State         Recv-Q        Send-Q               Local Address:Port                Peer Address:Port       Process
  3. LISTEN        0             128                      127.0.0.1:43789                    0.0.0.0:*           users:(("containerd",pid=318310,fd=15))
  4. LISTEN        0             128                        0.0.0.0:22                       0.0.0.0:*           users:(("sshd",pid=2773,fd=4))
  5. LISTEN        0             128                           [::]:22                          [::]:*           users:(("sshd",pid=2773,fd=6))
  6. [root@db170 ~]#
  7. [root@db170 ~]#
  8. [root@db170 ~]# docker run -d --name greatsql -p 3306:3306 --hostname=greatsql -e MYSQL_ALLOW_EMPTY_PASSWORD=1 greatsql/greatsql
  9. Unable to find image 'greatsql/greatsql:latest' locally
  10. latest: Pulling from greatsql/greatsql
  11. 7a0437f04f83: Pull complete
  12. 84a97b40a81d: Pull complete
  13. 13ca3f91447f: Pull complete
  14. d7cc4345a5d0: Pull complete
  15. 624ffe2a3f44: Pull complete
  16. d667df229764: Pull complete
  17. 65e680c20d42: Pull complete
  18. c5765aa0e9b0: Pull complete
  19. 94b9e84699a0: Pull complete
  20. 59847cdb6d61: Pull complete
  21. Digest: sha256:98037c4be9b953af2464301b97bfdb16b40dc03f050cba1ca837361f837abde4
  22. Status: Downloaded newer image for greatsql/greatsql:latest
  23. 19a5f934d0d27bd92a6d26b49ca2fc5e4381c14648cfffd912d85cdab50b0325
  24. [root@db170 ~]# ss -lntp  -- 查看监听,正常
  25. State        Recv-Q       Send-Q               Local Address:Port                Peer Address:Port       Process
  26. LISTEN       0            128                        0.0.0.0:3306                     0.0.0.0:*           users:(("docker-proxy",pid=1243285,fd=4))
  27. LISTEN       0            128                      127.0.0.1:43789                    0.0.0.0:*           users:(("containerd",pid=318310,fd=15))
  28. LISTEN       0            128                        0.0.0.0:22                       0.0.0.0:*           users:(("sshd",pid=2773,fd=4))
  29. LISTEN       0            128                           [::]:3306                        [::]:*           users:(("docker-proxy",pid=1243293,fd=4))
  30. LISTEN       0            128                           [::]:22                          [::]:*           users:(("sshd",pid=2773,fd=6))
  31. [root@db170 ~]# telnet 192.168.5.170 3306  -- 第一次telnet,失败
  32. Trying 192.168.5.170...
  33. telnet: connect to address 192.168.5.170: Connection refused

  34. [root@db170 ~]# docker ps -a   -- 查看映射,正常
  35. CONTAINER ID   IMAGE               COMMAND                  CREATED          STATUS                      PORTS                                                        NAMES
  36. 19a5f934d0d2   greatsql/greatsql   "/docker-entrypoint.…"   54 seconds ago   Up 48 seconds               0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060-33061/tcp   greatsql

  37. [root@db170 ~]# telnet 192.168.5.170 3306  -- 第二次成功,因为初始化好了
  38. Trying 192.168.5.170...
  39. Connected to 192.168.5.170.
  40. Escape character is '^]'.
  41. M
  42. 8.0.25-1b{#lr_{�+mc}Lcaching_sha2_password^]

  43. telnet>
  44. 2#08S01Got timeout reading communication packetsConnection closed by foreign host.
复制代码


可能的原因:GreatSQL Docker容器刚启动后,需要一定时间去完成初始化等工作,请耐心等几分钟后再尝试,尤其是当您的测试环境性能较低时,耗时要更久。
szhjb88 2024-3-4 11:36:17
yejr 发表于 2024-3-4 11:24
下面是我的操作过程,是正常的

你好,

我将一些不用的docker容器清理,重启docker服务,一切正常,谢谢
szhjb88

6

主题

0

博客

27

贡献

新手上路

Rank: 1

积分
47

助人为乐(铜)

合作电话:010-64087828

社区邮箱:greatsql@greatdb.com

社区公众号
社区小助手
QQ群
GMT+8, 2024-4-28 19:24 , Processed in 0.017412 second(s), 14 queries , Redis On.
快速回复 返回顶部 返回列表