2013:尝试连接时,“握手时与MySQL服务器的连接丢失:读取初始通信包,系统错误:115”

时间:2019-07-08 09:26:21

标签: bash docker mariadb dump entry-point

为mariadb转储创建映像。无法建立与mariadb容器的连接。我有一个运行MariaDB的容器。我正在开发用于定期创建数据库的MySQL转储的映像。 mariadump容器与MariaDB容器之间无法建立连接。

Docker-Compose

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 Dockerfile

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

1 个答案:

答案 0 :(得分:0)

如果要使容器能够通信,则应使用import ( "fmt" "github.com/tblyler/go-mcrypt" "encoding/base64" ) const ( KEY = "12345678901234567890123456789012" ENC = "Egu4tSySXluBLi5dcMzHbZHVSOS7jdNwUKUFlZ8dL1yATFjg26/Nav7cWtlJJL3djhUCND6KV8r/JL7owboKFA==" ) func main(){ encText, _ := base64.StdEncoding.DecodeString(ENC) iv := encText[:32] toDecrypt := encText[32:] fmt.Printf("Key Len: %d\n",len(KEY)) fmt.Printf("IV Len: %d\n",len(iv)) decText, err := mcrypt.Decrypt([]byte(KEY),iv,[]byte(toDecrypt)) if err != nil { panic(err) } fmt.Printf("%s\n",decText) } 属性。

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

建议,仅在配置文件中使用 snake_case