从另一个Docker容器连接到Docker容器中的mysql服务器

时间:2019-07-09 12:54:41

标签: python mysql docker

简而言之

在macOS Mojave中使用Dockers Desktop Community版本2.0.0.3(31259),我有两个容器:

我无法从Alpine泊坞窗访问在MySQL泊坞窗上运行的mysql服务器实例。

详细信息

在Alpine上,我正在运行python2和python软件包mysqlclient。这是我在python应用程序中用来访问mysql数据库的配置文件:

dbtype MySQLdb
connect-args {"user":"abe","db":"abe","passwd":"123"}
upgrade
host docker-mysql
port 32779

当我启动python应用程序时,我发现它无法连接到mysqld服务器,实际上我收到以下错误日志:

python -m Abe.abe --config abe-my.conf
Reconnecting after rollback error: (2002, "Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)")
Reconnecting to database.
Reconnecting after rollback error: (2002, "Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)")
Reconnecting to database.
Reconnecting after rollback error: (2002, "Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)")
Reconnecting to database.
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/bitcoin-abe/Abe/abe.py", line 2123, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/bitcoin-abe/Abe/abe.py", line 2117, in main
    store = make_store(args)
  File "/bitcoin-abe/Abe/abe.py", line 156, in make_store
    store = DataStore.new(args)
  File "Abe/DataStore.py", line 3427, in new
    return DataStore(args)
  File "Abe/DataStore.py", line 191, in __init__
    store.initialize()
  File "Abe/DataStore.py", line 637, in initialize
    store.configure()
  File "Abe/DataStore.py", line 944, in configure
    config = store._sql.configure()
  File "Abe/SqlAbstraction.py", line 643, in configure
    sql.configure_ddl_implicit_commit()
  File "Abe/SqlAbstraction.py", line 734, in configure_ddl_implicit_commit
    if sql._test_ddl():
  File "Abe/SqlAbstraction.py", line 741, in _test_ddl
    sql.drop_table_if_exists("%stest_1" % sql.prefix)
  File "Abe/SqlAbstraction.py", line 712, in drop_table_if_exists
    sql._drop_if_exists("TABLE", obj)
  File "Abe/SqlAbstraction.py", line 709, in _drop_if_exists
    sql.rollback()
  File "Abe/SqlAbstraction.py", line 632, in rollback
    sql.reconnect()
  File "Abe/SqlAbstraction.py", line 305, in reconnect
    return sql.conn()
  File "Abe/SqlAbstraction.py", line 288, in conn
    sql._conn = sql.connect()
  File "Abe/SqlAbstraction.py", line 249, in connect
    conn = sql._connect(cargs)
  File "Abe/SqlAbstraction.py", line 281, in _connect
    return sql.module.connect(**cargs)
  File "/usr/lib/python2.7/site-packages/MySQLdb/__init__.py", line 84, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/MySQLdb/connections.py", line 164, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)")

如何“固定”?

我看到访问文件是/run/mysqld/mysqld.sock,并且在mysql泊坞窗中找到了它,我想能够连接两个泊坞窗以使它们“互相看到”应该不是问题,但是目前我还不知道。

0 个答案:

没有答案