Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strapi ECONNREFUSED and ER_HOST_NOT_PRIVILEGED to StrapiDB container #86

Closed
borellif opened this issue Jul 5, 2023 · 6 comments
Closed
Assignees

Comments

@borellif
Copy link

borellif commented Jul 5, 2023

🐛 Bug Report

Hey all - I'm having trouble connecting my strapi container to my strapiDB container. My hunch is telling me it's a version issue or an environment variable not set but I'd love your help.

🤷‍♀️ What did you do

  1. Ran dockerize script using default configs except with MySQL, see details below:
fran@MacBook-Pro$ npx @strapi-community/dockerize
Need to install the following packages:
  @strapi-community/dockerize@1.15.3
Ok to proceed? (y) y

 @strapi-community/dockerize  v1.15.3 by Simen Daehlin
Easy add docker support for a Strapi Project
https://github.com/strapi-community/strapi-tool-dockerize

🎉  You, and 937 other people have used this tool this month

🍿  JavaScript project detected

📦  NPM detected

🚀  Strapi 4.9.0 detected

✔ Do you want to create a docker-compose file? 🐳 … No / Yes
✔ What environments do you want to configure? › Both
✔ Whats the name of the project? … strapi
✔ What database do you want to use? › MySQL
✔ Database Host … localhost
✔ Database Name … strapi
✔ Database Username … strapi
✔ Database Password … ********************
✔ Database Port … 3306
🐳  Checking for existing Docker files...

🐳  Found: .dockerignore, Dockerfile, Dockerfile.prod in project directory.

🪄   Moving .dockerignore to backup directory...

🪄   Moving Dockerfile to backup directory...

🪄   Moving Dockerfile.prod to backup directory...

📦  Backed up .dockerignore, Dockerfile, Dockerfile.prod

🐳  Added docker-compose file with MYSQL configuration

🕵️   Added Dockerize variables in .env

💾  Added MYSQL configuration to database.js

📦  Cleaned up old dependencies

📦  MYSQL dependencies installed with NPM

🐳  Checking for existing Docker files...

💁  No Dockerfiles found in the root directory. Skipping backup.

🐳  Dockerfile for development and production added

⭐️  Star the project on GitHub if you liked this tool 🙏

🎉  We now have got 312 🌟 and counting...

👉  https://github.com/strapi-community/strapi-tool-dockerize 👈

☕️ Feeling generious, feel free to buy me a ☕️ 👇

🙏 https://opencollective.com/strapi/projects/strapi-tool-dockerize
  1. Built docker container and sent it up, see details below:
fran@MacBook-Pro $ dc build
[+] Building 73.0s (14/14) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                               0.0s
 => => transferring dockerfile: 558B                                                                                                                                               0.0s
 => [internal] load .dockerignore                                                                                                                                                  0.0s
 => => transferring context: 99B                                                                                                                                                   0.0s
 => [internal] load metadata for docker.io/library/node:16-alpine                                                                                                                  0.5s
 => [1/9] FROM docker.io/library/node:16-alpine@sha256:6c381d5dc2a11dcdb693f0301e8587e43f440c90cdb8933eaaaabb905d44cdb9                                                            2.0s
 => => resolve docker.io/library/node:16-alpine@sha256:6c381d5dc2a11dcdb693f0301e8587e43f440c90cdb8933eaaaabb905d44cdb9                                                            0.0s
 => => sha256:5be700ca177e299682dae8239cef4872ee650f583f51ea76e9b49f02d8a64e67 36.45MB / 36.45MB                                                                                   0.8s
 => => sha256:f553329ee288f3a361bf66a33f364fe1897538ae9b914ff7b6e05ff3ddbede6f 2.34MB / 2.34MB                                                                                     0.4s
 => => sha256:e591100acf5b50227ef74124d46d23adfe12d3c67f9cb5f55fc122693c23a160 444B / 444B                                                                                         0.2s
 => => sha256:6c381d5dc2a11dcdb693f0301e8587e43f440c90cdb8933eaaaabb905d44cdb9 1.43kB / 1.43kB                                                                                     0.0s
 => => sha256:5164cbdc764902f95fbba6eb1bd67819a0a2827f0509c02d55b8ff3d8af26561 1.16kB / 1.16kB                                                                                     0.0s
 => => sha256:06340b3df0fbae8606cdf92e0aea6ef461360baed4926e963e36aa5bcb04f9be 6.75kB / 6.75kB                                                                                     0.0s
 => => extracting sha256:5be700ca177e299682dae8239cef4872ee650f583f51ea76e9b49f02d8a64e67                                                                                          0.9s
 => => extracting sha256:f553329ee288f3a361bf66a33f364fe1897538ae9b914ff7b6e05ff3ddbede6f                                                                                          0.1s
 => => extracting sha256:e591100acf5b50227ef74124d46d23adfe12d3c67f9cb5f55fc122693c23a160                                                                                          0.0s
 => [internal] load build context                                                                                                                                                  0.0s
 => => transferring context: 614.43kB                                                                                                                                              0.0s
 => [2/9] RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev                                                             7.1s
 => [3/9] WORKDIR /opt/                                                                                                                                                            0.0s
 => [4/9] COPY package.json package-lock.json ./                                                                                                                                   0.0s
 => [5/9] RUN npm config set network-timeout 600000 -g && npm install                                                                                                             33.2s
 => [6/9] WORKDIR /opt/app                                                                                                                                                         0.0s
 => [7/9] COPY . .                                                                                                                                                                 0.0s
 => [8/9] RUN chown -R node:node /opt/app                                                                                                                                          0.2s
 => [9/9] RUN ["npm", "run", "build"]                                                                                                                                             16.4s
 => exporting to image                                                                                                                                                            13.3s
 => => exporting layers                                                                                                                                                           13.3s
 => => writing image sha256:d2f2170acf0b66452cf7f9f5af881e3b78562464b5b8cdeec681fcaf35ed2981                                                                                       0.0s
 => => naming to docker.io/library/strapi:latest                                                                                                                                   0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
fran@MacBook-Pro $ dc up
[+] Running 12/12
 ⠿ strapiDB Pulled                                                                                                                                                                                    7.8s
   ⠿ e2c03c89dcad Pull complete                                                                                                                                                                       2.9s
   ⠿ 68eb43837bf8 Pull complete                                                                                                                                                                       3.0s
   ⠿ 796892ddf5ac Pull complete                                                                                                                                                                       3.1s
   ⠿ 6bca45eb31e1 Pull complete                                                                                                                                                                       3.2s
   ⠿ ebb53bc0dcca Pull complete                                                                                                                                                                       3.3s
   ⠿ 2e2c6bdc7a40 Pull complete                                                                                                                                                                       3.3s
   ⠿ 6f27b5c76970 Pull complete                                                                                                                                                                       4.8s
   ⠿ 438533a24810 Pull complete                                                                                                                                                                       4.8s
   ⠿ e5bdf19985e0 Pull complete                                                                                                                                                                       7.1s
   ⠿ 667fa148337b Pull complete                                                                                                                                                                       7.2s
   ⠿ 5baa702110e4 Pull complete                                                                                                                                                                       7.2s
[+] Running 4/4
 ⠿ Network Strapi           Created                                                                                                                                                                   0.1s
 ⠿ Container strapiDB       Created                                                                                                                                                                   0.2s
 ⠿ Container strapiAdminer  Created                                                                                                                                                                   0.1s
 ⠿ Container strapi         Created                                                                                                                                                          0.1s
Attaching to strapi, strapiAdminer, strapiDB

⛔️ Error log

The error comes in when the containers try to start, specifically the strapi container:

The error states that the connection is refused and the server restarts.

fran@MacBook-Pro ~/Projects/svelte/francisco-blog (main*) $ docker compose up
[+] Running 12/12
 ⠿ strapiDB Pulled                                                                                                                                                                                    7.8s
   ⠿ e2c03c89dcad Pull complete                                                                                                                                                                       2.9s
   ⠿ 68eb43837bf8 Pull complete                                                                                                                                                                       3.0s
   ⠿ 796892ddf5ac Pull complete                                                                                                                                                                       3.1s
   ⠿ 6bca45eb31e1 Pull complete                                                                                                                                                                       3.2s
   ⠿ ebb53bc0dcca Pull complete                                                                                                                                                                       3.3s
   ⠿ 2e2c6bdc7a40 Pull complete                                                                                                                                                                       3.3s
   ⠿ 6f27b5c76970 Pull complete                                                                                                                                                                       4.8s
   ⠿ 438533a24810 Pull complete                                                                                                                                                                       4.8s
   ⠿ e5bdf19985e0 Pull complete                                                                                                                                                                       7.1s
   ⠿ 667fa148337b Pull complete                                                                                                                                                                       7.2s
   ⠿ 5baa702110e4 Pull complete                                                                                                                                                                       7.2s
[+] Running 4/4
 ⠿ Network Strapi           Created                                                                                                                                                                   0.1s
 ⠿ Container strapiDB       Created                                                                                                                                                                   0.2s
 ⠿ Container strapiAdminer  Created                                                                                                                                                                   0.1s
 ⠿ Container strapi         Created                                                                                                                                                                   0.1s
Attaching to strapi, strapiAdminer, strapiDB
strapiDB       | 2023-07-05 16:50:54+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.33-1.el8 started.
strapiAdminer  | [Wed Jul  5 16:50:55 2023] PHP 7.4.33 Development Server (http://[::]:8080) started
strapi         | 
strapi         | > francisco-blog@0.1.0 develop
strapi         | > strapi develop
strapi         | 
strapiDB       | 2023-07-05 16:50:56+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
strapiDB       | 2023-07-05 16:50:56+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.33-1.el8 started.
strapi         | [2023-07-05 16:50:58.402] debug: ⛔️ Server wasn't able to start properly.
strapi         | [2023-07-05 16:50:58.403] error: connect ECONNREFUSED 172.24.0.2:3306
strapi         | Error: connect ECONNREFUSED 172.24.0.2:3306
strapi         |     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1278:16)
strapi         |     --------------------
strapi         |     at Protocol._enqueue (/opt/node_modules/mysql/lib/protocol/Protocol.js:144:48)
strapi         |     at Protocol.handshake (/opt/node_modules/mysql/lib/protocol/Protocol.js:51:23)
strapi         |     at Connection.connect (/opt/node_modules/mysql/lib/Connection.js:116:18)
strapi         |     at /opt/node_modules/knex/lib/dialects/mysql/index.js:66:18
strapi         |     at new Promise (<anonymous>)
strapi         |     at Client_MySQL.acquireRawConnection (/opt/node_modules/knex/lib/dialects/mysql/index.js:61:12)
strapi         |     at create (/opt/node_modules/knex/lib/client.js:254:39)
strapi exited with code 1
strapi         | 
strapi         | > francisco-blog@0.1.0 develop
strapi         | > strapi develop
strapi         | 
strapiDB       | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
strapiDB       | 2023-07-05T16:50:59.739003Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
strapiDB       | 2023-07-05T16:50:59.746238Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
strapiDB       | 2023-07-05T16:50:59.746583Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.33) starting as process 1
strapiDB       | 2023-07-05T16:50:59.864327Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
strapiDB       | 2023-07-05T16:50:59.899114Z 1 [ERROR] [MY-012585] [InnoDB] Linux Native AIO interface is not supported on this platform. Please check your OS documentation and install appropriate binary of InnoDB.
strapiDB       | 2023-07-05T16:50:59.899452Z 1 [Warning] [MY-012654] [InnoDB] Linux Native AIO disabled.
strapiDB       | 2023-07-05T16:51:00.230449Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
strapiDB       | 2023-07-05T16:51:01.322589Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
strapiDB       | 2023-07-05T16:51:01.323925Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
strapiDB       | 2023-07-05T16:51:01.337354Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
strapiDB       | 2023-07-05T16:51:01.518597Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
strapiDB       | 2023-07-05T16:51:01.521092Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.33'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
strapi         | [2023-07-05 16:51:02.149] debug: ⛔️ Server wasn't able to start properly.
strapi         | [2023-07-05 16:51:02.151] error: ER_HOST_NOT_PRIVILEGED: Host '172.24.0.4' is not allowed to connect to this MySQL server
strapi         | Error: ER_HOST_NOT_PRIVILEGED: Host '172.24.0.4' is not allowed to connect to this MySQL server
strapi         |     at Handshake.Sequence._packetToError (/opt/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
strapi         |     at Handshake.ErrorPacket (/opt/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
strapi         |     at Protocol._parsePacket (/opt/node_modules/mysql/lib/protocol/Protocol.js:291:23)
strapi         |     at Parser._parsePacket (/opt/node_modules/mysql/lib/protocol/Parser.js:433:10)
strapi         |     at Parser.write (/opt/node_modules/mysql/lib/protocol/Parser.js:43:10)
strapi         |     at Protocol.write (/opt/node_modules/mysql/lib/protocol/Protocol.js:38:16)
strapi         |     at Socket.<anonymous> (/opt/node_modules/mysql/lib/Connection.js:88:28)
strapi         |     at Socket.<anonymous> (/opt/node_modules/mysql/lib/Connection.js:526:10)
strapi         |     at Socket.emit (node:events:513:28)
strapi         |     at Socket.emit (node:domain:489:12)
strapi         |     --------------------
strapi         |     at Protocol._enqueue (/opt/node_modules/mysql/lib/protocol/Protocol.js:144:48)
strapi         |     at Protocol.handshake (/opt/node_modules/mysql/lib/protocol/Protocol.js:51:23)
strapi         |     at Connection.connect (/opt/node_modules/mysql/lib/Connection.js:116:18)
strapi         |     at /opt/node_modules/knex/lib/dialects/mysql/index.js:66:18
strapi         |     at new Promise (<anonymous>)
strapi         |     at Client_MySQL.acquireRawConnection (/opt/node_modules/knex/lib/dialects/mysql/index.js:61:12)
strapi         |     at create (/opt/node_modules/knex/lib/client.js:254:39)
strapi exited with code 1

🕵️‍♀️ Stack trace

strapiDB       | 2023-07-05 16:50:54+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.33-1.el8 started.
strapiAdminer  | [Wed Jul  5 16:50:55 2023] PHP 7.4.33 Development Server (http://[::]:8080) started
strapi         | 
strapi         | > francisco-blog@0.1.0 develop
strapi         | > strapi develop
strapi         | 
strapiDB       | 2023-07-05 16:50:56+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
strapiDB       | 2023-07-05 16:50:56+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.33-1.el8 started.
strapi         | [2023-07-05 16:50:58.402] debug: ⛔️ Server wasn't able to start properly.
strapi         | [2023-07-05 16:50:58.403] error: connect ECONNREFUSED 172.24.0.2:3306
strapi         | Error: connect ECONNREFUSED 172.24.0.2:3306
strapi         |     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1278:16)
strapi         |     --------------------
strapi         |     at Protocol._enqueue (/opt/node_modules/mysql/lib/protocol/Protocol.js:144:48)
strapi         |     at Protocol.handshake (/opt/node_modules/mysql/lib/protocol/Protocol.js:51:23)
strapi         |     at Connection.connect (/opt/node_modules/mysql/lib/Connection.js:116:18)
strapi         |     at /opt/node_modules/knex/lib/dialects/mysql/index.js:66:18
strapi         |     at new Promise (<anonymous>)
strapi         |     at Client_MySQL.acquireRawConnection (/opt/node_modules/knex/lib/dialects/mysql/index.js:61:12)
strapi         |     at create (/opt/node_modules/knex/lib/client.js:254:39)
strapi exited with code 1
strapi         | 
strapi         | > francisco-blog@0.1.0 develop
strapi         | > strapi develop
strapi         | 
strapiDB       | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
strapiDB       | 2023-07-05T16:50:59.739003Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
strapiDB       | 2023-07-05T16:50:59.746238Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
strapiDB       | 2023-07-05T16:50:59.746583Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.33) starting as process 1
strapiDB       | 2023-07-05T16:50:59.864327Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
strapiDB       | 2023-07-05T16:50:59.899114Z 1 [ERROR] [MY-012585] [InnoDB] Linux Native AIO interface is not supported on this platform. Please check your OS documentation and install appropriate binary of InnoDB.
strapiDB       | 2023-07-05T16:50:59.899452Z 1 [Warning] [MY-012654] [InnoDB] Linux Native AIO disabled.
strapiDB       | 2023-07-05T16:51:00.230449Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
strapiDB       | 2023-07-05T16:51:01.322589Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
strapiDB       | 2023-07-05T16:51:01.323925Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
strapiDB       | 2023-07-05T16:51:01.337354Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
strapiDB       | 2023-07-05T16:51:01.518597Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
strapiDB       | 2023-07-05T16:51:01.521092Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.33'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
strapi         | [2023-07-05 16:51:02.149] debug: ⛔️ Server wasn't able to start properly.
strapi         | [2023-07-05 16:51:02.151] error: ER_HOST_NOT_PRIVILEGED: Host '172.24.0.4' is not allowed to connect to this MySQL server
strapi         | Error: ER_HOST_NOT_PRIVILEGED: Host '172.24.0.4' is not allowed to connect to this MySQL server
strapi         |     at Handshake.Sequence._packetToError (/opt/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
strapi         |     at Handshake.ErrorPacket (/opt/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
strapi         |     at Protocol._parsePacket (/opt/node_modules/mysql/lib/protocol/Protocol.js:291:23)
strapi         |     at Parser._parsePacket (/opt/node_modules/mysql/lib/protocol/Parser.js:433:10)
strapi         |     at Parser.write (/opt/node_modules/mysql/lib/protocol/Parser.js:43:10)
strapi         |     at Protocol.write (/opt/node_modules/mysql/lib/protocol/Protocol.js:38:16)
strapi         |     at Socket.<anonymous> (/opt/node_modules/mysql/lib/Connection.js:88:28)
strapi         |     at Socket.<anonymous> (/opt/node_modules/mysql/lib/Connection.js:526:10)
strapi         |     at Socket.emit (node:events:513:28)
strapi         |     at Socket.emit (node:domain:489:12)
strapi         |     --------------------
strapi         |     at Protocol._enqueue (/opt/node_modules/mysql/lib/protocol/Protocol.js:144:48)
strapi         |     at Protocol.handshake (/opt/node_modules/mysql/lib/protocol/Protocol.js:51:23)
strapi         |     at Connection.connect (/opt/node_modules/mysql/lib/Connection.js:116:18)
strapi         |     at /opt/node_modules/knex/lib/dialects/mysql/index.js:66:18
strapi         |     at new Promise (<anonymous>)
strapi         |     at Client_MySQL.acquireRawConnection (/opt/node_modules/knex/lib/dialects/mysql/index.js:61:12)
strapi         |     at create (/opt/node_modules/knex/lib/client.js:254:39)
strapi exited with code 1

🙇‍♀️ Expected behavior/code

Have the strapi and strapiDB containers be able to speak to each other and connect

👩‍💻 Environment

Dev environment

  • 📦 Node version: v18.15.0
  • 💻 OS: Mac OS Ventura 13.4.1 - Apple M1 Pro

💡 Possible Solution

N/A

📺 Additional context/Screenshots

I did have this setup with mysql locally and the container complained that the port 3306 was already in use. I turned off my local non-docker mysql instance.

I also checked my mysql environment variables:

fran@macbook-pro ~/Projects/svelte/francisco-blog (main*) $ docker exec -it 20b4ebc358d9 bash
bash-4.4# env
_=/usr/bin/env
DATABASE_PASSWORD=[MY DB PASSWORD]
MYSQL_SHELL_VERSION=8.0.33-1.el8
DATABASE_HOST=localhost
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
TRANSFER_TOKEN_SALT=[MY TRANSFER TOKEN SALT]
SHLVL=1
ADMIN_JWT_SECRET=[MY ADMIN JWT SECRET]
DATABASE_USERNAME=strapi
TERM=xterm
DATABASE_NAME=strapi
MYSQL_VERSION=8.0.33-1.el8
PORT=1337
JWT_SECRET=[MY JWT SECRET]
DATABASE_PORT=3306
HOST=0.0.0.0
MYSQL_USER=strapi
GOSU_VERSION=1.16
MYSQL_MAJOR=8.0
HOME=/root
PWD=/
APP_KEYS=[MY APP KEYS]
MYSQL_ROOT_PASSWORD=[MY MYSQL PASSWORD]
NODE_ENV=development
DATABASE_CLIENT=mysql
MYSQL_DATABASE=strapi
API_TOKEN_SALT=[MY API TOKEN SALT]
HOSTNAME=20b4ebc358d9
MYSQL_PASSWORD=[MY MYSQL PASSWORD]

and my strapi env variables (before the container exits):

6c78bac24eb1:/opt/app$ env
HOSTNAME=6c78bac24eb1
YARN_VERSION=1.22.19
PWD=/opt/app
DATABASE_NAME=strapi
PORT=1337
NODE_ENV=development
HOME=/home/node
ADMIN_JWT_SECRET=[ADMIN JWT SECRET]
DATABASE_PORT=3306
TERM=xterm
HOST=0.0.0.0
DATABASE_CLIENT=mysql
DATABASE_PASSWORD=[DB PASSWORD]
DATABASE_USERNAME=strapi
SHLVL=1
DATABASE_HOST=strapiDB
TRANSFER_TOKEN_SALT=[TRANSFER TOKEN SALT]
API_TOKEN_SALT=[API TOKEN SALT]
APP_KEYS=[API KEYS]
PATH=/opt/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
JWT_SECRET=[JWT SECRET]
NODE_VERSION=16.20.1
_=/usr/bin/env

Finally - I changed the node version of my dockerfiles to use node:18-alpine

Please let me know if you have questions, I appreciate your help.

@borellif
Copy link
Author

borellif commented Jul 5, 2023

I'll also attach the dockerfile and the docker-compose file that were created as part of the script:

Dockerfile:

FROM node:18-alpine
# Installing libvips-dev for sharp Compatibility
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev
ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}

WORKDIR /opt/
COPY package.json package-lock.json ./
RUN npm config set network-timeout 600000 -g && npm install

WORKDIR /opt/app
COPY . .
ENV PATH /opt/node_modules/.bin:$PATH
RUN chown -R node:node /opt/app
USER node
RUN ["npm", "run", "build"]
EXPOSE 1337
CMD ["npm", "run", "develop"]

docker-compose.yml

version: '3'
services:
  strapi:
    container_name: strapi
    build: .
    image: strapi:latest
    restart: unless-stopped
    env_file: .env
    environment:
      DATABASE_CLIENT: ${DATABASE_CLIENT}
      DATABASE_HOST: strapiDB
      DATABASE_NAME: ${DATABASE_NAME}
      DATABASE_USERNAME: ${DATABASE_USERNAME}
      DATABASE_PORT: ${DATABASE_PORT}
      JWT_SECRET: ${JWT_SECRET}
      ADMIN_JWT_SECRET: ${ADMIN_JWT_SECRET}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD}
      NODE_ENV: ${NODE_ENV}
    volumes:
      - ./config:/opt/app/config
      - ./src:/opt/app/src
      - ./package.json:/opt/package.json
      - ./package-lock.json:/opt/package-lock.json

      - ./.env:/opt/app/.env
      - ./public/uploads:/opt/app/public/uploads
    ports:
      - '1337:1337'
    networks:
      - strapi
    depends_on:
      - strapiDB
      
  strapiDB:
    container_name: strapiDB
    platform: linux/amd64 #for platform error on Apple M1 chips
    restart: unless-stopped
    env_file: .env
    image: mysql:latest
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_USER: ${DATABASE_USERNAME}
      MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD}
      MYSQL_PASSWORD: ${DATABASE_PASSWORD}
      MYSQL_DATABASE: ${DATABASE_NAME}
    volumes:
      - strapi-data:/var/lib/mysql
      #- ./data:/var/lib/postgresql/data/ # if you want to use a bind folder
    ports:
      - '3306:3306'
    networks:
      - strapi
      
  strapiAdminer:
    container_name: strapiAdminer
    image: adminer
    restart: unless-stopped
    ports:
      - '9090:8080'
    environment:
      - ADMINER_DEFAULT_SERVER=strapiDB
    networks:
      - strapi
    depends_on:
      - strapiDB

volumes:
  strapi-data:

networks:
  strapi:
    name: Strapi
    driver: bridge

@Eventyret
Copy link
Member

Seems the issue is from here

ER_HOST_NOT_PRIVILEGED: Host '172.24.0.4' is not allowed to connect to this MySQL server strapi | Error: ER_HOST_NOT_PRIVILEGED: Host '172.24.0.4' is not allowed to connect to this MySQL server

What's the docker compose file look like if I can ask? Your env looks correct etc though it seems it's the authentication in MySQL that's the issue.

@borellif
Copy link
Author

borellif commented Jul 5, 2023

After digging a bit deeper it seems that the docker mysql server will only accept connections from 'root' unless specified otherwise in the docker compose.

Here is some documentation from MySQL when setting that up - https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html#docker_var_mysql-root-host

I have a potential solution in the strapiDB docker-compose configuration:

strapiDB:
    container_name: strapiDB
    platform: linux/amd64 #for platform error on Apple M1 chips
    restart: unless-stopped
    env_file: .env
    image: mysql:latest
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_USER: ${DATABASE_USERNAME}
      MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD}
      MYSQL_PASSWORD: ${DATABASE_PASSWORD}
      MYSQL_DATABASE: ${DATABASE_NAME}
      MYSQL_ROOT_HOST: '%'

Where MYSQL_ROOT_HOST: '%' is new. I guess this can be added to the database.js in the /config/env folder or in the .env file

@borellif
Copy link
Author

borellif commented Jul 5, 2023

Seems the issue is from here

ER_HOST_NOT_PRIVILEGED: Host '172.24.0.4' is not allowed to connect to this MySQL server strapi | Error: ER_HOST_NOT_PRIVILEGED: Host '172.24.0.4' is not allowed to connect to this MySQL server

What's the docker compose file look like if I can ask? Your env looks correct etc though it seems it's the authentication in MySQL that's the issue.

Saw this too late, but the docker compose file is in my second comment. I added the environment variable of MYSQL_ROOT_HOST. This probably can be done programmatically. Docker IPs tend to be 172.x.x.x but I did just see a 192.x.x.x range as well. This also, however, looks like it can be configured.

@Eventyret
Copy link
Member

Thank you will add a small fix to it with % seems this is on the newest version of MySQL that it was changed so.
Thank you for a detailed report and glad you got it fixed.

@Eventyret
Copy link
Member

I have added MYSQL_ROOT_HOST: '%' into the last update so closing this issue.

Eventyret added a commit that referenced this issue Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants