这是LARAVEL项目的设置:
文档文件:
FROM php:8.1.2-cli-buster
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN apt-get update && apt install git -y
WORKDIR /var/www/html
COPY . .
RUN composer install --no-dev
RUN mv ./.env.example .env
RUN php artisan key:generate
CMD ["/bin/bash", "-c", "php artisan serve --host 0.0.0.0 --port 8000"]
查看docker-Compse.yml中的这个变量
version: "3.8"
services:
artisan:
build: .
environment:
CUSTOM_VAR: custom-value-from-compse
ports:
- '8000:8000'
Api.php
Route::get('test', function () {
dump(env('CUSTOM_VAR')); //CUSTOM_VAR is null
});
上面的路由应该转储custom-value-from-compse
值,但它转储了1d1d1e,这是什么问题?它只覆盖.env
文件中的现有变量,我的意思是如果我在.env文件中将CUSTOM_VAR
设置为‘Some-Value’,它不会覆盖它为docker Compose内部的值
注意:CUSTOM_VAR
将为空,即使我将其放入Dockerfile中...
1条答案
按热度按时间von4xj4u1#
或许可以试试这个:
消息来源:https://gist.github.com/kevinyan815/fa0760902d29f19a4213b4a16fe0501b#file-docker-compose-yml-for-laravel-L11