在 docker 下运行 laravel 5 的错误
Posted
技术标签:
【中文标题】在 docker 下运行 laravel 5 的错误【英文标题】:Errors running laravel 5 under docker 【发布时间】:2019-05-16 22:49:33 【问题描述】:我尝试在 docker 下安装 laravel 5.0/mysql"5.5"/php_version,但我无法在浏览器中进行定位并为应用程序播种: 我有 3 个配置文件: docker-compose.yml :
version: '3.1'
services:
youtube_api_demo_app:
build:
context: ./web
dockerfile: Dockerfile.yml
container_name: youtube_api_demo_app_container
environment:
- APACHE_RUN_USER=#1000
volumes:
- $APP_PATH_HOST:$APP_PTH_CONTAINER
ports:
- 8085:80
working_dir: $APP_PTH_CONTAINER
db:
image: mysql:5.5.62
restart: always
environment:
MYSQL_ROOT_PASSWORD: 1
volumes:
- $DB_PATH_HOST:/var/lib/mysql
adminer:
image: adminer
restart: always
ports:
- 8086:8080
links:
- db
youtube_api_demo_composer:
image: composer:1.6
container_name: youtube_api_demo_composer_container
volumes:
- $APP_PATH_HOST:$APP_PTH_CONTAINER
working_dir: $APP_PTH_CONTAINER
command: composer install --ignore-platform-reqs
.env:
# PATHS
DB_PATH_HOST=./databases
APP_PATH_HOST=./YoutubeAPI_Demo
APP_PTH_CONTAINER=/var/www/html/
web/Dockerfile.yml:
FROM php:5.6-apache
RUN apt-get update -y && apt-get install -y libpng-dev nano libmcrypt-dev
RUN docker-php-ext-install \
pdo_mysql \
mcrypt \
&& a2enmod \
rewrite
和我的应用程序 /YoutubeAPI_Demo/.env 的环境:
APP_NAME=Laravel APP_ENV=本地 APP_KEY=base64:4+BRJbKtSQ7Z7yBVkYxe+NxfLkVPBAG2Gm1I93Qwukc= APP_DEBUG=true APP_URL=http://127.0.0.1:8085/APP_SUBDIRECTORY=
LOG_CHANNEL=堆栈
DB_USERNAME=root DB_PASSWORD=1 DB_CONNECTION=mysql DB_HOST=127.0.0.1:8086 DB_PORT=:8086 DB_DATABASE=youtube_api_demo
我不确定我是否设置了有效的 DB_HOST 和 DB_PORT 参数,实际上我尝试了不同的。
1) 我构建了应用程序并进入了控制台,但我在迁移时出错:
# php artisan migrate
[PDOException]
SQLSTATE[HY000] [2002] Connection refused
但是我进入了adminer并创建了db:https://imgur.com/a/ePBfMiv
2) 在浏览器中输入http://127.0.0.1:8085/ 出现错误:
You don't have permission to access / on this server.
Apache/2.4.25 (Debian) Server at 127.0.0.1 Port 8085
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a51ccd12ae40 adminer "entrypoint.sh docke…" About an hour ago Up About an hour 0.0.0.0:8086->8080/tcp youtubeapi_demo_adminer_1
7f9ee8f14c9d mysql:5.5.62 "docker-entrypoint.s…" About an hour ago Up About an hour 3306/tcp youtubeapi_demo_db_1
b2c47edaf616 youtubeapi_demo_youtube_api_demo_app "docker-php-entrypoi…" About an hour ago Up About an hour 0.0.0.0:8085->80/tcp youtube_api_demo_app_container
3dcc1a4ce8f0 adminer "entrypoint.sh docke…" 5 weeks ago Up 4 hours 0.0.0.0:8083->8080/tcp lprods_adminer_container
933d9fffaf76 postgres:9.6.10-alpine "docker-entrypoint.s…" 5 weeks ago Up 4 hours 0.0.0.0:5433->5432/tcp lprods_db_container
2f73a600b999 adminer "entrypoint.sh docke…" 6 weeks ago Up 4 hours 0.0.0.0:8082->8080/tcp votes_docker_adminer_1
52ea479b8791 mysql:5.6.41 "docker-entrypoint.s…" 6 weeks ago Restarting (1) 34 seconds ago votes_docker_db_1
配置选项有什么问题?
谢谢!
【问题讨论】:
【参考方案1】:1) 在 .env 中:您可以使用:
DB_CONNECTION=mysql
DB_HOST=db // THAT IS MYSQL container name
DB_PORT=3306
2) 试试网址
http://127.0.0.1:8085/public
使用通常的 laravel 5 目录设置
【讨论】:
以上是关于在 docker 下运行 laravel 5 的错误的主要内容,如果未能解决你的问题,请参考以下文章
使用 docker-compose 在 Docker 中运行 laravel/lumen
如何在 Docker 上运行 Laravel (Lumen) 调度程序
如何在 laravel 应用程序中使用 docker 容器启动运行 websockets