Problems when running docker-compose

Hi!!!.. I have got a trouble executing a docker-compose. I will tell that I don’t have much experience in this environment, It is very difficult for me to solve the incidents that arise when I practice on my own.

Well, I have a docker-compose whick it runs two images: one executes node, and the other executes mySql:

version: “3.7”
services:
app:
image: dockeresteban/getting-started:v2
ports:
- 3000:3000
environment:
MYSQL_HOST: mysql
MYSQL_USER: root
MYSQL_PASSWORD: secret
MYSQL_DB: todos
mysql:
image: mysql:5.7
volumes:
- ./todo-mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: todos

The question is that when I execute “docker-compose up -d”, the containers begin to run in the machine, if I write in the bash: docker ps" I see:

esteban@esteban-VirtualBox:~/proyectos/peladonerd/docker/12/multi-container$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
811dfda4ae22 mysql:5.7 “docker-entrypoint.s…” 19 seconds ago Up 17 seconds 3306/tcp, 33060/tcp multi-container_mysql_1
2ac3940b6b3d dockeresteban/getting-started:v2 “docker-entrypoint.s…” 19 seconds ago Up 18 seconds 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp multi-container_app_1

But If I look at the logs of my node’s container (getting-started:v2), the system response:

Waiting for mysql:3306…
Timeout
Error: Handshake inactivity timeout
at Handshake. (/app/node_modules/mysql/lib/protocol/Protocol.js:160:17)
at Handshake.emit (events.js:314:20)
at Handshake._onTimeout (/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:124:8)
at Timer._onTimeout (/app/node_modules/mysql/lib/protocol/Timer.js:32:23)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
--------------------
at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at PoolConnection.connect (/app/node_modules/mysql/lib/Connection.js:119:18)
at Pool.getConnection (/app/node_modules/mysql/lib/Pool.js:48:16)
at Pool.query (/app/node_modules/mysql/lib/Pool.js:202:8)
at /app/src/persistence/mysql.js:35:14
at new Promise ()
at Object.init (/app/src/persistence/mysql.js:34:12)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
code: ‘PROTOCOL_SEQUENCE_TIMEOUT’,
fatal: true,
timeout: 10000
}

And finally the container downs for itself.

The dockerfile is:

FROM node:12.22.1-alpine3.11
WORKDIR /app
COPY . .
RUN yarn install --production
CMD [“node”, “/app/src/index.js”]

For the response I suppose that the problem comes from the Protocol of the mysql database, but I don’t know how I can change the response time and put more seconds time, I’m looking fot the system file, but I don’t find It. I don’t know if this fix will solve this problem either.

Thanks to everywhere!.

The way you formatted this post makes it incredibly hard to read.
But i think you’re missing something here, it says timeout to the mysql container, but what is the state of the mysql container? logs?

Sorry for my post!!!, I’m going to format in other way to read better…

My docker-compose:

version: “3.7”

services:
  mysql:
    image: mysql:5.7
    volumes:
      - ./todo-mysql-data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: todos  
  app:
    image: dockeresteban/getting-started:v2
    ports:
      - 3000:3000
    restart: always
    environment:
      MYSQL_HOST: mysql
      MYSQL_USER: root
      MYSQL_PASSWORD: secret
      MYSQL_DB: todos
    depends_on:
      - mysql

The Dockerfile that creates the node image:

FROM node 12.22.1-alpine3.11
WORKDIR /app
COPY . . 
RUN yarn install --production

And I changed my docker-compose with “restart: always” to the node’s container don’t down, but the output log is the same, “handshake inactivity timeout”, repeat and repeat and repeat…

Waiting for mysql:3306........
Timeout
Error: Handshake inactivity timeout
    at Handshake.<anonymous> (/app/node_modules/mysql/lib/protocol/Protocol.js:160:17)
    at Handshake.emit (events.js:314:20)
    at Handshake._onTimeout (/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:124:8)
    at Timer._onTimeout (/app/node_modules/mysql/lib/protocol/Timer.js:32:23)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
    --------------------
    at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at PoolConnection.connect (/app/node_modules/mysql/lib/Connection.js:119:18)
    at Pool.getConnection (/app/node_modules/mysql/lib/Pool.js:48:16)
    at Pool.query (/app/node_modules/mysql/lib/Pool.js:202:8)
    at /app/src/persistence/mysql.js:35:14
    at new Promise (<anonymous>)
    at Object.init (/app/src/persistence/mysql.js:34:12)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  code: 'PROTOCOL_SEQUENCE_TIMEOUT',
  fatal: true,
  timeout: 10000
}

These is mysql logs:

esteban@esteban-VirtualBox:~/proyectos/multi-container$ docker logs 20ab740cbac7
2022-12-22 13:52:47+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.40-1.el7 started.
2022-12-22 13:52:48+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-12-22 13:52:48+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.40-1.el7 started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2022-12-22T13:52:48.980714Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-12-22T13:52:48.981990Z 0 [Note] mysqld (mysqld 5.7.40) starting as process 1 ...
2022-12-22T13:52:48.989175Z 0 [Note] InnoDB: PUNCH HOLE support available
2022-12-22T13:52:48.989304Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-12-22T13:52:48.989308Z 0 [Note] InnoDB: Uses event mutexes
2022-12-22T13:52:48.989310Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2022-12-22T13:52:48.989311Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.12
2022-12-22T13:52:48.989312Z 0 [Note] InnoDB: Using Linux native AIO
2022-12-22T13:52:48.989530Z 0 [Note] InnoDB: Number of pools: 1
2022-12-22T13:52:48.989624Z 0 [Note] InnoDB: Using CPU crc32 instructions
2022-12-22T13:52:48.991168Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2022-12-22T13:52:48.996442Z 0 [Note] InnoDB: Completed initialization of buffer pool
2022-12-22T13:52:48.998497Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2022-12-22T13:52:49.025577Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2022-12-22T13:52:49.026491Z 0 [Note] InnoDB: Log scan progressed past the checkpoint lsn 12177294
2022-12-22T13:52:49.026565Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 12177303
2022-12-22T13:52:49.026569Z 0 [Note] InnoDB: Database was not shutdown normally!
2022-12-22T13:52:49.026571Z 0 [Note] InnoDB: Starting crash recovery.
2022-12-22T13:52:49.158461Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2022-12-22T13:52:49.158476Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2022-12-22T13:52:49.158500Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2022-12-22T13:52:49.203289Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2022-12-22T13:52:49.203898Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2022-12-22T13:52:49.203908Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2022-12-22T13:52:49.204361Z 0 [Note] InnoDB: Waiting for purge to start
2022-12-22T13:52:49.255529Z 0 [Note] InnoDB: 5.7.40 started; log sequence number 12177303
2022-12-22T13:52:49.256280Z 0 [Note] Plugin 'FEDERATED' is disabled.
2022-12-22T13:52:49.256502Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2022-12-22T13:52:49.281131Z 0 [Note] InnoDB: Buffer pool(s) load completed at 221222 13:52:49
2022-12-22T13:52:49.294046Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2022-12-22T13:52:49.294096Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2022-12-22T13:52:49.294101Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-12-22T13:52:49.294102Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-12-22T13:52:49.298200Z 0 [Warning] CA certificate ca.pem is self signed.
2022-12-22T13:52:49.298279Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2022-12-22T13:52:49.298455Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2022-12-22T13:52:49.298475Z 0 [Note] IPv6 is available.
2022-12-22T13:52:49.298505Z 0 [Note]   - '::' resolves to '::';
2022-12-22T13:52:49.298516Z 0 [Note] Server socket created on IP: '::'.
2022-12-22T13:52:49.303590Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2022-12-22T13:52:49.310760Z 0 [Note] Event Scheduler: Loaded 0 events
2022-12-22T13:52:49.311206Z 0 [Note] mysqld: ready for connections.
Version: '5.7.40'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
2022-12-22T15:42:08.648843Z 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 6035055ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.)