I've built a docker-compose file that creates 2 services (PHP and MariaDB).
(我已经构建了一个docker-compose文件,该文件创建了2个服务(PHP和MariaDB)。)
Somehow I cannot connect to the database from the PHP service: Within the PHP service, a Laravel-app is running. (我无法以某种方式从PHP服务连接到数据库:在PHP服务中,一个Laravel应用程序正在运行。)
The error message (redirect is a table within the database):
(错误消息(重定向是数据库中的表):)
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from redirects
)
(SQLSTATE [HY000] [2002]连接被拒绝(SQL:从redirects
选择*))
All env-variables should be correct.
(所有环境变量都应正确。)
Here is my docker-compose.yml:
(这是我的docker-compose.yml:)
version: "3.7"
services:
faaren_backend:
image: php:alpine
container_name: FAA-Backend
volumes:
- "./:/faaren_backend"
working_dir: /faaren_backend
command: "php artisan serve --host=0.0.0.0 --port=8000"
ports:
- 8000:8000
build:
context: docker/php
dockerfile: dev.Dockerfile
faaren_database:
image: mariadb
container_name: FAA-Database
ports:
- "3306:3306"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
MYSQL_DATABASE: ${DB_DATABASE}
volumes:
- "faa-db-data:/var/lib/mysql/data"
volumes:
faa-db-data: {}
My dev.Dockerfile
(我的开发人员Dockerfile)
FROM php:7.3-fpm
RUN apt-get update
RUN apt-get update && apt-get install -y libzip-dev
&& docker-php-ext-install zip
RUN apt-get update && apt-get install -y libmagickwand-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN pecl install imagick
RUN docker-php-ext-enable imagick
RUN apt-get install $PHPIZE_DEPS &&
pecl install xdebug && docker-php-ext-enable xdebug &&
docker-php-ext-install pdo_mysql pcntl
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
VOLUME /faaren_backend
And finally my .env-file:
(最后是我的.env文件:)
DB_CONNECTION=mysql
DB_HOST=faaren_backend
DB_PORT=3306
DB_DATABASE=faaren_db
DB_USERNAME=root
DB_PASSWORD=
Mostly I've followed this tutorial: https://medium.com/swlh/laravel-with-docker-compose-de2190569084
(大多数情况下,我都遵循本教程: https : //medium.com/swlh/laravel-with-docker-compose-de2190569084)
ask by Brotzka translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…