我正在使用Laravel开发Web应用程序。我是经验丰富的Laravel开发人员。但是,现在我正在尝试使用Docker作为开发环境。但是我对Docker非常陌生。现在,我正在尝试连接到Postgres数据库。我也在docker-composer.yml中添加了Postgres docker镜像。但是,当我运行迁移时,出现错误,并且未连接到数据库。
这是我的docker-compose.xml文件。
version: '2'
services:
web:
build:
context: ./
dockerfile: docker/web.docker
volumes:
- ./:/var/www
ports:
- "80:80"
- "443:443"
- "9000:9000"
links:
- app
app:
build:
context: ./
dockerfile: docker/app.docker
volumes:
- ./:/var/www
links:
- mysql
- redis
- beanstalk
- cache
environment:
- "DB_PORT=3306"
- "DB_HOST=mysql"
- "REDIS_PORT=6379"
- "REDIS_HOST=redis"
mysql:
image: mysql:5.7.18
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=docker"
ports:
- "3306:3306"
pgsql:
image: postgres:10.1
restart: always
environment:
- POSTGRES_DB=docker
- POSTGRES_USER=root
- POSTGRES_PASSWORD=secret
ports:
- 5431:5431
volumes:
- ./.docker/conf/postgres/:/docker-entrypoint-initdb.d/
redis:
image: redis:3.0
ports:
- "6379:6379"
beanstalk:
image: schickling/beanstalkd
ports:
- "11300:11300"
cache:
image: memcached:alpine
ports:
- "11211:11211"
我知道我也添加了Mysql映像。当我连接到Mysql映像时,它正在工作。当我连接到Postgres时,出现错误。
这是我在env文件中用于连接到Postgres的数据库设置。
DB_CONNECTION=pgsql
DB_HOST=pgsql
DB_PORT=5431
DB_DATABASE=docker
DB_USERNAME=root
DB_PASSWORD=secret
当我在这样的终端中运行迁移时
docker-compose exec app php artisan migrate --seed
我收到此错误。
In Connection.php line 647:
could not find driver (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations)
In PDOConnection.php line 50:
could not find driver
In PDOConnection.php line 46:
could not find driver
我的安装有什么问题?
答案 0 :(得分:0)
您没有添加docker / app.docker详细信息,但是如果这正在运行PHP,则需要确保在此容器上同时安装了php7-pgsql和php7-pdo。驱动程序通常只是phpX-mysql或phpX-pgsql。 X是可选的版本号,具体取决于您用于php的存储库。即使用默认的ubuntu repo php-pgsql就可以了,但是对于高山图像,您必须使用php7-pgsql。 使用sury repo,您必须使用特定版本,即php7.2-pgsql。