-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Comments
I'll also attach the dockerfile and the docker-compose file that were created as part of the script: Dockerfile:
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 |
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. |
After digging a bit deeper it seems that the docker mysql server will only accept connections from 'root' unless specified otherwise in the 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 |
Saw this too late, but the docker compose file is in my second comment. I added the environment variable of |
Thank you will add a small fix to it with % seems this is on the newest version of MySQL that it was changed so. |
I have added |
… to connect yo mysql container re #86
🐛 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
⛔️ 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.
🕵️♀️ Stack trace
🙇♀️ Expected behavior/code
Have the strapi and strapiDB containers be able to speak to each other and connect
👩💻 Environment
Dev environment
💡 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:
and my strapi env variables (before the container exits):
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.
The text was updated successfully, but these errors were encountered: