我使用的码头工人,撰写试图与蟒蛇的连接MariaDB的:
泊坞窗,compose.yml
version: '2'
services:
mariadb:
image: bitnami/mariadb
ports:
- "3306:3306"
environment:
MARIADB_DATABASE: 'mary_db'
MARIADB_USER: user2
MARIADB_PASSWORD: 'pass1234'
consumer:
build: ./consumer
links:
- mariadb
consumer.py
import mysql.connector as mariadb1
mariadb_connection = mariadb1.connect(host='mariadb',
port=3306,
user='user2',
password='pass1234',
database='mary_db')
cursor = mariadb_connection.cursor(buffered=True)
try:
cursor.execute('DROP TABLE names')
except:
pass
comm = "CREATE TABLE names(id VARCHAR(20), location VARCHAR(100)," \
"PRIMARY KEY (mac,location)) ENGINE=InnoDB"
cursor.execute(comm)
print 'created'
该Dockerfile入口点仅仅是调用像consumer.py功能:
ENTRYPOINT python -u consumer.py
问题是非常随机(超过试验的90%),Python代码不能与数据库和打印此错误连接:
文件“consumer.py”,第7行,在数据库= 'mary_db')文件“/usr/local/lib/python2.7/dist-packages/mysql/connector/ INIT py”为,线179,在连接返回的MySqlConnection (*指定参数时,** kwargs)文件“/usr/local/lib/python2.7/dist-packages/mysql/connector/connection.py”,线路95,在初始化 self.connect(** kwargs)文件“/ USR /本地/ LIB / python2.7 / DIST-包/ MySQL的/连接器/ abstracts.py “线路719,在连接self._open_connection()文件” /usr/local/lib/python2.7/dist-packages/ MySQL的/连接器/ connection.py”,线路206,在_open_connection self._socket.open_connection()文件 “/usr/local/lib/python2.7/dist-packages/mysql/connector/network.py”,线路475,在OPEN_CONNECTION错误号= 2003,值=(self.get_address(),_strioerror(ERR)))mysql.connector.errors.InterfaceError:2003:无法连接到MySQL服务器 'MariaDB的:3306'(111连接被拒绝)
任何想法是怎么回事?