как подключить бд к приложению docker?

Подскажите пожалуйста, кто может
код будет доступен на github
Есть приложение(скрипт на Python) , которое доваляет запись в БД(Mysql),
оба разбиты на два контейнера, но запускаются через один docker-compose
в документации выычетал, что если у приложений один компос, то они могут связываться между собой по именам контейнеров.
но к сожалению не могу свзать два контейнера между собой, в логах вижу что mysql работает, подключиться к нему тоже получается, а вот скрипт python выходит с ошибкой 1, по логам видно, что подключиться к БД ему не удается, подскажите пожалуйста, как исправить данную ошибку ?
и как вообще лучше всго производить подключение к БД из другого контейнера?
если у Вас есть пример, буду очень признателен
логи при запуске
```
Creating network "docker_default" with the default driver
Creating docker_python-test_1 ... done
Creating docker_bd_1 ... done
Attaching to docker_bd_1, docker_python-test_1
bd_1 | 2021-01-18 14:24:31+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.22-1debian10 started.
bd_1 | 2021-01-18 14:24:31+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
bd_1 | 2021-01-18 14:24:32+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.22-1debian10 started.
python-test_1 | Traceback (most recent call last):
python-test_1 | File "/usr/local/lib/python3.9/site-packages/pymysql/connections.py", line 613, in connect
python-test_1 | sock = socket.create_connection(
python-test_1 | File "/usr/local/lib/python3.9/socket.py", line 843, in create_connection
python-test_1 | raise err
python-test_1 | File "/usr/local/lib/python3.9/socket.py", line 831, in create_connection
python-test_1 | sock.connect(sa)
python-test_1 | ConnectionRefusedError: [Errno 111] Connection refused
python-test_1 |
python-test_1 | During handling of the above exception, another exception occurred:
python-test_1 |
python-test_1 | Traceback (most recent call last):
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2336, in wrap_pool_connect
python-test_1 | return fn()
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 364, in connect
python-test_1 | return _ConnectionFairy._checkout(self)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 778, in _checkout
python-test_1 | fairy = _ConnectionRecord.checkout(pool)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 495, in checkout
python-test_1 | rec = pool._do_get()
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/impl.py", line 140, in _do_get
python-test_1 | self._dec_overflow()
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit_
python-test_1 | compat.raise_(
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
python-test_1 | raise exception
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/impl.py", line 137, in do_get
python-test_1 | return self._create_connection()
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 309, in _create_connection
python-test_1 | return _ConnectionRecord(self)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 440, in __init_
python-test_1 | self.connect(first_connect_check=True)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 661, in __connect
python-test_1 | pool.logger.debug("Error on connect(): %s", e)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit
python-test_1 | compat.raise_(
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
python-test_1 | raise exception
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 656, in connect
python-test_1 | connection = pool._invoke_creator(self)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
python-test_1 | return dialect.connect(*cargs, **cparams)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 509, in connect
python-test_1 | return self.dbapi.connect(*cargs, **cparams)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/pymysql/connections.py", line 353, in __init
python-test_1 | self.connect()
python-test_1 | File "/usr/local/lib/python3.9/site-packages/pymysql/connections.py", line 664, in connect
python-test_1 | raise exc
python-test_1 | pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'bd' ([Errno 111] Connection refused)")
python-test_1 |
python-test_1 | The above exception was the direct cause of the following exception:
python-test_1 |
python-test_1 | Traceback (most recent call last):
python-test_1 | File "/usr/src/app/main.py", line 23, in <module>
python-test_1 | Base.metadata.create_all(engine)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 4553, in create_all
python-test_1 | bind.run_visitor(
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2094, in _run_visitor
python-test_1 | with self._optional_conn_ctx_manager(connection) as conn:
python-test_1 | File "/usr/local/lib/python3.9/contextlib.py", line 117, in __enter_
python-test_1 | return next(self.gen)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2086, in optional_conn_ctx_manager
python-test_1 | with self._contextual_connect() as conn:
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2302, in _contextual_connect
python-test_1 | self._wrap_pool_connect(self.pool.connect, None),
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2339, in _wrap_pool_connect
python-test_1 | Connection._handle_dbapi_exception_noconnection(
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1583, in _handle_dbapi_exception_noconnection
python-test_1 | util.raise(
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
python-test_1 | raise exception
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2336, in wrap_pool_connect
python-test_1 | return fn()
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 364, in connect
python-test_1 | return _ConnectionFairy._checkout(self)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 778, in _checkout
python-test_1 | fairy = _ConnectionRecord.checkout(pool)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 495, in checkout
python-test_1 | rec = pool._do_get()
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/impl.py", line 140, in _do_get
python-test_1 | self._dec_overflow()
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit_
python-test_1 | compat.raise_(
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
python-test_1 | raise exception
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/impl.py", line 137, in do_get
python-test_1 | return self._create_connection()
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 309, in _create_connection
python-test_1 | return _ConnectionRecord(self)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 440, in __init_
python-test_1 | self.connect(first_connect_check=True)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 661, in __connect
python-test_1 | pool.logger.debug("Error on connect(): %s", e)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit
python-test_1 | compat.raise_(
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
python-test_1 | raise exception
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 656, in connect
python-test_1 | connection = pool._invoke_creator(self)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
python-test_1 | return dialect.connect(*cargs, **cparams)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 509, in connect
python-test_1 | return self.dbapi.connect(*cargs, **cparams)
python-test_1 | File "/usr/local/lib/python3.9/site-packages/pymysql/connections.py", line 353, in __init
python-test_1 | self.connect()
python-test_1 | File "/usr/local/lib/python3.9/site-packages/pymysql/connections.py", line 664, in connect
python-test_1 | raise exc
python-test_1 | sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'bd' ([Errno 111] Connection refused)")
python-test_1 | (Background on this error at: http://sqlalche.me/e/13/e3q8)
bd_1 | 2021-01-18T14:24:32.329923Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.22) starting as process 1
bd_1 | 2021-01-18T14:24:32.338897Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
docker_python-test_1 exited with code 1
bd_1 | 2021-01-18T14:24:32.553959Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
bd_1 | 2021-01-18T14:24:32.658501Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
bd_1 | 2021-01-18T14:24:32.775114Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
bd_1 | 2021-01-18T14:24:32.775502Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
bd_1 | 2021-01-18T14:24:32.781791Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
bd_1 | 2021-01-18T14:24:32.811456Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.22' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.