我创建了一个Docker,并且运行良好。 但是,当我尝试在Laravel中使用数据库时。它返回找不到它的错误。
这是我的docker文件。和我得到的错误。而“ docker ps”结果。
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
这是我的“ .env”文件。
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}"
这是我的“ docker ps”结果。
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失败:提供了节点名或服务名,或者未知(SQL:select * from information_schema.tables,其中table_schema = spor和table_name = migrations并且table_type ='BASE TABLE')
“异常跟踪:
1 PDOException::(“ PDO :: __ construct():php_network_getaddresses:getaddrinfo失败:提供了节点名或服务名,或者未知”) /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 “
我的数据库连接可能有什么问题?