2013: "Lost connection to MySQL server at 'handshake: reading inital communication packet', system error: 115" when trying to connect
2013: "Lost connection to MySQL server at 'handshake: reading inital communication packet', system error: 115" when trying to connect
正在为 mariadb 转储创建图像。无法与 mariadb 容器建立连接。我有一个容器 运行 MariaDB。我正在开发我的图像以定期创建 MySQL 数据库转储。无法建立 mariadump 容器和 MariaDB 容器之间的连接。
Docker-撰写
version: '3.3'
services:
db:
# image: 'mariadb'
build: ./mariadbimage
container_name: MariaDB
volumes:
- db_data:/var/lib/mysql
# - ./etc/localtime:/etc/localtime:ro
# - ./opt/mysql/backup:/opt/mysql/backup
ports:
- "3306:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
mariadump:
container_name: MariaDump
build: ./mariadumpimage
environment:
TZ: Europe/Berlin
volumes:
- ./ssh:/root/.ssh
depends_on:
- db
links:
- db
MariaDump Docker文件
FROM mariadb/server
RUN apt-get update && apt-get -y install cron curl openssh-client
ENV TINI_VERSION v0.17.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
ADD scripts /usr/local/bin/
RUN chmod 0755 /usr/local/bin/mariadumper.sh /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["/tini", "-e", "143", "--", "docker-entrypoint.sh"]
Mariadump 入口点
MYSQL_USER=wordpress
MYSQL_PASSWORD=wordpress
MYSQL_HOST=host.docker.internal
MYSQL_PORT=3306
BACKUP_FILE=/var/backups/$(date +"%Y-%m-%d-%H%M%S")_${MYSQL_HOST}_mysqldump
MYSQL_OPTS="-u${MYSQL_USER} -p${MYSQL_PASSWORD} -h${MYSQL_HOST} -P${MYSQL_PORT}"
MYSQLDUMP_OPTS="--single-transaction --routines --triggers"
mysqldump ${MYSQL_OPTS} ${MYSQLDUMP_OPTS} --all-databases >${BACKUP_FILE}
RETVAL=$?
if [ "$RETVAL" == 0 ]; then
echo Compressing backup using gzip compression method.
gzip --best ${BACKUP_FILE}*
RETVAL=$?
fi
if [ "$RETVAL" == 0 ]; then
echo Backup finished successfully.
exit 0
else
echo Backup failed with errors!
exit 1
fi
错误:
Got error: 2013: "Lost connection to MySQL server at 'handshake: reading inital communication packet', system error: 115" when trying to connect
如果你想让容器能够通信,你应该使用networks
属性.
version: '3.3'
services:
db:
# image: 'mariadb'
build: ./mariadbimage
container_name: MariaDB
volumes:
- db_data:/var/lib/mysql
# - ./etc/localtime:/etc/localtime:ro
# - ./opt/mysql/backup:/opt/mysql/backup
ports:
- "3306:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- my-network-name
mariadump:
container_name: MariaDump
build: ./mariadumpimage
environment:
TZ: Europe/Berlin
volumes:
- ./ssh:/root/.ssh
depends_on:
- db
links:
- db
networks:
- my-network-name
networks:
my-network-name:
driver: bridge
然后容器可以使用 container-name
或 id
:
相互发送请求
http://MariaDB:3306/
作为建议,在配置文件中仅使用 snake_case。
正在为 mariadb 转储创建图像。无法与 mariadb 容器建立连接。我有一个容器 运行 MariaDB。我正在开发我的图像以定期创建 MySQL 数据库转储。无法建立 mariadump 容器和 MariaDB 容器之间的连接。
Docker-撰写
version: '3.3'
services:
db:
# image: 'mariadb'
build: ./mariadbimage
container_name: MariaDB
volumes:
- db_data:/var/lib/mysql
# - ./etc/localtime:/etc/localtime:ro
# - ./opt/mysql/backup:/opt/mysql/backup
ports:
- "3306:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
mariadump:
container_name: MariaDump
build: ./mariadumpimage
environment:
TZ: Europe/Berlin
volumes:
- ./ssh:/root/.ssh
depends_on:
- db
links:
- db
MariaDump Docker文件
FROM mariadb/server
RUN apt-get update && apt-get -y install cron curl openssh-client
ENV TINI_VERSION v0.17.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
ADD scripts /usr/local/bin/
RUN chmod 0755 /usr/local/bin/mariadumper.sh /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["/tini", "-e", "143", "--", "docker-entrypoint.sh"]
Mariadump 入口点
MYSQL_USER=wordpress
MYSQL_PASSWORD=wordpress
MYSQL_HOST=host.docker.internal
MYSQL_PORT=3306
BACKUP_FILE=/var/backups/$(date +"%Y-%m-%d-%H%M%S")_${MYSQL_HOST}_mysqldump
MYSQL_OPTS="-u${MYSQL_USER} -p${MYSQL_PASSWORD} -h${MYSQL_HOST} -P${MYSQL_PORT}"
MYSQLDUMP_OPTS="--single-transaction --routines --triggers"
mysqldump ${MYSQL_OPTS} ${MYSQLDUMP_OPTS} --all-databases >${BACKUP_FILE}
RETVAL=$?
if [ "$RETVAL" == 0 ]; then
echo Compressing backup using gzip compression method.
gzip --best ${BACKUP_FILE}*
RETVAL=$?
fi
if [ "$RETVAL" == 0 ]; then
echo Backup finished successfully.
exit 0
else
echo Backup failed with errors!
exit 1
fi
错误:
Got error: 2013: "Lost connection to MySQL server at 'handshake: reading inital communication packet', system error: 115" when trying to connect
如果你想让容器能够通信,你应该使用networks
属性.
version: '3.3'
services:
db:
# image: 'mariadb'
build: ./mariadbimage
container_name: MariaDB
volumes:
- db_data:/var/lib/mysql
# - ./etc/localtime:/etc/localtime:ro
# - ./opt/mysql/backup:/opt/mysql/backup
ports:
- "3306:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- my-network-name
mariadump:
container_name: MariaDump
build: ./mariadumpimage
environment:
TZ: Europe/Berlin
volumes:
- ./ssh:/root/.ssh
depends_on:
- db
links:
- db
networks:
- my-network-name
networks:
my-network-name:
driver: bridge
然后容器可以使用 container-name
或 id
:
http://MariaDB:3306/
作为建议,在配置文件中仅使用 snake_case。