问题
I am trying to deploy my node js application with docker but when I am running the docker compose it giving an error at the end. There is an issue in MySQL.I am running the command in terminal:
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;
error (Terminal output):
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:
After run the docker-compose please check:
docker ps
You will find your mysql container run correctly and test to connect inside of your container to check if the database are created
docker exec -it container_name /bin/bash
mysql -u root
show databases;
The problem occured when node try to attach db.
Attaching to mydb, autokab_helicopter-api_1
I suggest to:
- Remove images you built mysql and node
- Rebuild mysql only and test if it works properly
- Don't forget to use volume on mysql container :'/var/lib/mysql' to not lose you data.
- if mysql work properly now you can launch node container
Hope it helps
来源:https://stackoverflow.com/questions/56664660/mysql-give-error-when-running-the-docker-composer-node-js