运行docker composer时mysql给出错误-节点js

时间:2019-06-19 09:41:01

标签: mysql docker docker-compose dockerfile mysql-error-1064

我试图用docker部署我的node js应用程序,但是当我运行docker时,它组成了一个错误。 MySQL中有问题。我正在终端中运行命令:

  

docker-compose up --build

docker-compose.yml

version: '3'
services:
  db:
    build:
      context: .
      dockerfile: ./docker/Dockerfile-mysql
    container_name: mydb
    command: --explicit_defaults_for_timestamp=1
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
      - MYSQL_DATABASE=dbautokab
      - MYSQL_USER=root
      - MYSQL_PASSWORD=
    networks:
      - helicopter-network
    healthcheck:
      test: "exit 0"

  helicopter-api:
    build:
      context: .
      dockerfile: ./docker/Dockerfile-api
    depends_on:
      - db
    networks: ['helicopter-network']
    environment:
        - PORT=3000
        - DATABASE_HOST=db
        - DATABASE_PASSWORD=
        - EGG_SERVER_ENV=local
        - NODE_ENV=development
    ports:
      - "3000:3000"

networks:
  helicopter-network:
    driver: bridge

Dockerfile-api

FROM node:10-slim

USER node

RUN mkdir -p /home/node/app

WORKDIR /home/node/app

COPY --chown=node package*.json ./

RUN npm install

COPY --chown=node . .

COPY wait-for-it.sh /

ENV HOST=0.0.0.0 PORT=3000

EXPOSE ${PORT}

CMD /wait-for-it.sh db:3306 -- npm start

Dockerfile-mysql

FROM mysql:5.7.26

COPY ./docker/init_db.sql /docker-entrypoint-initdb.d/

init_db.sql

CREATE DATABASE IF NOT EXISTS dbautokab;
GRANT ALL PRIVILEGES on dbautokab.*
TO 'root'@'%'
WITH GRANT OPTION;

错误(终端输出):

Attaching to mydb, autokab_helicopter-api_1
mydb              | 2019-06-19T09:20:34.704713Z 0 [Note] mysqld     (mysqld 5.7.26) starting as process 1 ...
mydb              | 2019-06-19T09:20:34.708930Z 0 [Note] InnoDB: PUNCH HOLE support available
mydb              | 2019-06-19T09:20:34.708962Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mydb              | 2019-06-19T09:20:34.708977Z 0 [Note] InnoDB: Uses event mutexes
mydb              | 2019-06-19T09:20:34.708991Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mydb              | 2019-06-19T09:20:34.709016Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
mydb              | 2019-06-19T09:20:34.709043Z 0 [Note] InnoDB: Using Linux native AIO
mydb              | 2019-06-19T09:20:34.709674Z 0 [Note] InnoDB: Number of pools: 1
mydb              | 2019-06-19T09:20:34.709895Z 0 [Note] InnoDB: Using CPU crc32 instructions
mydb              | 2019-06-19T09:20:34.711940Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
mydb              | 2019-06-19T09:20:34.729374Z 0 [Note] InnoDB: Completed initialization of buffer pool
mydb              | 2019-06-19T09:20:34.732229Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
mydb              | 2019-06-19T09:20:34.747795Z 0 [ERROR] [FATAL] InnoDB: Table flags are 0 in the data dictionary but the flags in file ./ibdata1 are 0x4800!
mydb              | 2019-06-19 09:20:34 0x7f811365e740  InnoDB: Assertion failure in thread 140192352954176 in file ut0ut.cc line 942
mydb              | InnoDB: We intentionally generate a memory trap.
mydb              | InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
mydb              | InnoDB: If you get repeated assertion failures or crashes, even
mydb              | InnoDB: immediately after the mysqld startup, there may be
mydb              | InnoDB: corruption in the InnoDB tablespace. Please refer to
mydb              | InnoDB: http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html
mydb              | InnoDB: about forcing recovery.
mydb              | 09:20:34 UTC - mysqld got signal 6 ;
mydb              | This could be because you hit a bug. It is also possible that this binary
mydb              | or one of the libraries it was linked against is corrupt, improperly built,
mydb              | or misconfigured. This error can also be caused by malfunctioning hardware.
mydb              | Attempting to collect some information that could help diagnose the problem.
mydb              | As this is a crash and something is definitely wrong, the information
mydb              | collection process might fail.

1 个答案:

答案 0 :(得分:0)

运行docker-compose后,请检查:

  

docker ps

您会发现您的mysql容器运行正常,并进行测试以连接到容器内部以检查是否已创建数据库

  

docker exec -it container_name / bin / bash

     

mysql -u根

     

显示数据库;

节点尝试附加数据库时发生问题。

Attaching to mydb, autokab_helicopter-api_1

我建议:

  • 删除您构建的mysql和node图像
  • 仅重建mysql并测试其是否正常运行
  • 别忘了在mysql容器上使用volume:'/ var / lib / mysql'不会丢失数据。
  • 如果mysql现在可以正常工作,则可以启动节点容器

希望有帮助