mysql 在运行 docker Composer - Node js 时出现错误

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

我正在尝试使用 docker 部署我的 Node js 应用程序,但是当我运行 docker compose 时,它​​最后会出现错误。 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.

最佳答案

运行 docker-compose 后请检查:

docker ps

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

docker exec -it container_name /bin/bash

mysql -u root

show databases;

节点尝试附加数据库时出现问题。

Attaching to mydb, autokab_helicopter-api_1

我建议:

  • 删除您构建的 mysql 和 node 镜像
  • 仅重建mysql并测试其是否正常工作
  • 不要忘记在 mysql 容器:'/var/lib/mysql' 上使用卷,以免丢失数据。
  • 如果 mysql 现在工作正常,您可以启动节点容器

希望对你有帮助

关于mysql 在运行 docker Composer - Node js 时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56664660/

相关文章:

postgresql - 如何使用纯 docker-compose 将 PostGIS 添加到我的 PostgreSQL 设置中

azure - 如何从 docker-compose 构建输出中提取图像名称和标签

docker - 如何在 Docker 容器中自动重启 golang 应用程序?

nginx - 使用 Let's encrypt 获得的 SSL 证书的访问权限

php - 如何从 php 表单中的单选按钮获取值并检查另一个 php 中的值

python - 使用默认 Python 测试 MySQL 连接

php - 查询未更新,不确定原因

php - 跳过导入 csv 的第一行

Docker:将 Linux korn Shell 添加到现有容器

docker - Dockerfile运行lpadmin以添加无法在构建镜像中运行的打印机吗?