this is my docker.yml file
services:
web:
image: app-name:latest
build:
target: web
context: .
env_file:
- .env
ports:
- "8000:80"
volumes:
- .:/var/www/html
depends_on:
- db
db:
image: mysql:8.0
ports:
- 3307:3307
expose:
- "3307"
cap_add:
- SYS_NICE
command: --skip-grant-tables
volumes:
- ./cache/mysql:/var/lib/mysql
- ./conf-mysql.cnf:/etc/mysql/conf.d/mysql.cnf
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=chat
restart: unless-stopped
volumes:
dbdata:
this is my database file config in .env
DB_CONNECTION=mysql
DB_HOST=host.docker.internal
# DB_HOST=db
DB_PORT=3307
DB_DATABASE=chat
DB_USERNAME=root
DB_PASSWORD=password
i have tried db as well host.docker.internal. but unable to resolve this issue your text
SQLSTATE[HY000] [2006] MySQL server has gone away
i want to connect of my docter app to database`your text“
3
Answers
I see a couple of issues. When using docker, you should use the service name as the host. In your case, that would be ‘db’. So in your .env file, use:
You’re exposing MySQL on port 3307, but the standard MySQL port is 3306. Change the MySQL port to 3306
then in your
.env
file:Use localhost as DB Host.
check container-id
only first 4 characters required.
check logs using this command. Eg.
Try
.env