我的 dockerized Lumen 项目响应时间很慢,因此根据建议,我将项目从经典路径 C:\Mgr\lumen_laravel\lumenmysql 移至 \ \wsl.localhost\Ubuntu\home\samo\lumenmysql,然后创建 Z:\ 驱动器,以便我可以在该位置打开终端并运行“docker-compose up -d”。在以前的地址中它可以正常工作。我没有更改任何代码,但出现了错误。有什么建议吗?谢谢。
docker 中的错误
2023-03-21 22:49:00 AH00112:警告:DocumentRoot [/var/www/html/public] 不存在
根据 docker inspect Mount info它存在
/VAR/WWW/HTML Z:\home\samo\lumenmysql
docker-compose.yml
version: '3.8'
services:
mysqldb:
image: mysql:5.7
container_name : mysqldb
restart: always
volumes:
- ${DOCKER_MYSQL_VOLUME:-/opt/db_data}:/var/lib/mysql
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: diplomovka
MYSQL_ROOT_PASSWORD: 1234
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
environment:
PMA_HOST: mysqldb
DB_READ_HOST: mysqldb
ports:
- "3400:80"
depends_on:
- mysqldb
app:
container_name: Lumen
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/var/www/html
restart: ${DOCKER_RESTART_POLICY:-always}
ports:
- "9000:80"
working_dir: /var/www/html
environment:
MYSQL_HOST: mysqldb
MYSQL_USER: root
MYSQL_PASSWORD: 1234
MYSQL_PORT: 3306
虚拟主机配置文件
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/html/public
<Directory "/var/www/html">
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Dockerfile
FROM php:7.4.19-apache
WORKDIR /var/www/html
RUN apt-get update && apt-get install -y \
zlib1g-dev \
libzip-dev \
libonig-dev \
curl \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install mysqli \
&& docker-php-source delete
COPY ./vhost.conf /etc/apache2/sites-available/000-default.conf
COPY ./ ./
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN chown -R www-data:www-data /var/www/html \
&& a2enmod rewrite
RUN cd /var/www/html && composer install && php artisan key:generate
答案1
WSL2
这是您的环境和窗口之间的路径映射问题env
,使用Z:\
驱动器而不是路径/mnt/c
。
这是您的更新docker-compose.yml
文件:
version: '3.8'
services:
mysqldb:
image: mysql:5.7
container_name : mysqldb
restart: always
volumes:
- ${DOCKER_MYSQL_VOLUME:-/opt/db_data}:/var/lib/mysql
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: diplomovka
MYSQL_ROOT_PASSWORD: 1234
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
environment:
PMA_HOST: mysqldb
DB_READ_HOST: mysqldb
ports:
- "3400:80"
depends_on:
- mysqldb
app:
container_name: Lumen
build:
context: .
dockerfile: Dockerfile
volumes:
- /mnt/c/Mgr/lumen_laravel/lumenmysql:/var/www/html
restart: ${DOCKER_RESTART_POLICY:-always}
ports:
- "9000:80"
working_dir: /var/www/html
environment:
MYSQL_HOST: mysqldb
MYSQL_USER: root
MYSQL_PASSWORD: 1234
MYSQL_PORT: 3306
答案2
解决方案是
volumes:
- \\wsl.localhost\Ubuntu\home\samo\lumenmysql:/var/www/html