Can’t connect docker mysql – php_network_getaddresses

I created a Docker and worked well.
But when I tried to use database with Laravel. It returns error that couldnt find it.

Here’s my docker file. And errors that i get. And “docker ps” result.

version: '3.1'
services:
  redis:
    image: "redis:alpine"
    ports:
      - 6379/tcp
    networks:
      spordev:
        ipv4_address: 172.25.0.2
  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 11235
      MYSQL_DATABASE: spor
      MYSQL_USER: spor
      MYSQL_PASSWORD: 11235
    networks:
      spordev:
        ipv4_address: 172.25.0.3
  web:
    build: .
    ports:
      - "3000:80"
    volumes:
      - .:/var/www/html
    networks:
      spordev:
        ipv4_address: 172.25.0.4

networks:
  spordev:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.25.0.0/16

Here’s my “.env” file.

APP_NAME=Spor
APP_ENV=local
APP_KEY=base64:cs9fOYhNYy4Jtp3VurVN3XWN7qXk0yxWlLh3cPuIU20=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=spor
DB_USERNAME=root
DB_PASSWORD=11235

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
QUEUE_CONNECTION=sync
SESSION_DRIVER=redis
SESSION_LIFETIME=120

REDIS_CLIENT=predis
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=
MAIL_PORT=587
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=
MAIL_FROM_NAME=

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

and here’s my “docker ps” result.

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                            NAMES
3e745f1eb06a        mysql               "docker-entrypoint.s…"   14 minutes ago      Up 2 minutes        3306/tcp, 33060/tcp              spor_db_1
502f3f77f24c        spor_web            "/usr/bin/supervisor…"   14 minutes ago      Up 2 minutes        9000/tcp, 0.0.0.0:3000->80/tcp   spor_web_1
55bbd344b18a        redis:alpine        "docker-entrypoint.s…"   14 minutes ago      Up 2 minutes        0.0.0.0:32769->6379/tcp          spor_redis_1

“SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known (SQL: select * from information_schema.tables where table_schema = spor and table_name = migrations and table_type = ‘BASE TABLE’)”

” Exception trace:

1 PDOException::(“PDO::__construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known”)
/Users/tufancagkansokmen/works/spor/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

2 PDO::__construct(“mysql:host=db;port=3306;dbname=spor”, “spor”, “11235”, [])
/Users/tufancagkansokmen/works/spor/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

What could be problem about my database connection?

Source: StackOverflow