【问题标题】:000-default.conf not found while building docker image of Laravel app on windows在 Windows 上构建 Laravel 应用程序的 docker 映像时找不到 000-default.conf
【发布时间】:2022-01-11 14:55:44
【问题描述】:

我正在尝试按照给定的教程使用 docker 映像在 AWS 上部署我的 Laravel 应用程序:

https://medium.com/@okekedesmond/deploying-containerized-laravel-application-using-aws-ec2-instances-with-docker-and-rds-883e8f6d6245

在构建 docker 映像时,我一开始就卡住了。这是我的 Dockerfile:

#  Defining the base image for our project, if you understand how docker images and layers work, this should not be difficult to understand. 
FROM php:7.3-cli
# We need to update the  image and install some import packages
RUN apt-get update -y && apt-get install -y openssl zip unzip git curl libpng-dev libonig-dev libxml2-dev
# cleaning packages and install scripts
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Installing composer which is used to install Laravel
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin –filename=composer
#Creating a configuration file for apache and linking
ADD 000-default.conf /etc/apache2/sites-available/
RUN ln -sf /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/000-default.conf 

#Restarting Apache
RUN a2enmod rewrite
RUN service apache2 restart
# Create a work directory and copy all project file into the 
WORKDIR /var/www/app/
COPY . /var/www/app
#Granting permissions to files and folders
RUN chmod -R o+w /var/www/app/storage
RUN chown -R www-data:www-data ./storage
RUN chgrp -R www-data storage bootstrap/cache
RUN chmod -R ug+rwx storage bootstrap/cache
RUN chmod -R 755 /var/www/app/
RUN find /var/www/app/ -type d -exec chmod 775 {} \;
RUN chown -R www-data:www-data /var/www
# Installing dependencies from laravel package 
RUN composer install --no-scripts --no-autoloader --no-ansi --no-interaction --working-dir=/var/www/app
#Running some packages 
RUN docker-php-ext-install mbstring pdo pdo_mysql mbstring exif pcntl bcmath gd opcache
#Running Laravel on docker, because we are using the php-7.3-cli so we have to use a php server in our docker image
CMD php artisan serve --host=0.0.0.0 --port=80
EXPOSE 80`

在第 1 步出现错误。 5:

Step 5/21 : ADD 000-default.conf /etc/apache2/sites-available/
ADD failed: file not found in build context or excluded by .dockerignore: stat 000-default.conf: file does not exist

如何在 Windows 上解决它?任何帮助将不胜感激

【问题讨论】:

  • 你不能在特定目录中手动制作一个吗?
  • 那是我在问我应该在哪里制作这个 000-default.conf 文件?在 Laravel 项目文件夹中?就像我在窗户上一样
  • 我只是在 ubuntu 上使用了 apache2,但我认为它并没有什么不同。要放入的目录已经在您的错误消息中。它是/etc/apache2/sites-available/
  • 虽然我不是 100% 确定,但也许你可以 google 一下

标签: php laravel docker apache


【解决方案1】:

我认为最好的解决方案是手动新建一个,这是一个示例文件:

https://gist.github.com/tjtoml/942d696c868b22a25259

它应该位于:

/etc/apache2/sites-available/000-default.conf

您可能必须根据自己的需要对其进行自定义

【讨论】:

  • 你能告诉我我应该把这个文件放在windows的什么地方,以便在创建图像时docker会添加这个文件吗?我应该将此文件放在放置 Dockerfile 的 laravel 根文件夹中吗?
  • 不看你的目录结构就很难判断。你的 Windows 机器上安装了 apache2 吗?
  • 得到了问题。我想我没有使用任何 wsl2,因此它不起作用
  • 现在可以使用了吗? :) 几天前我在 ubuntu 上设置 apache2 时遇到了很大的问题,所以当你能够解决它时我很高兴 :)
  • 是的,解决了。我第一次在 docker 上工作,这是一个令人费解的游戏:D
猜你喜欢
  • 2021-08-31
  • 2016-05-27
  • 2022-09-28
  • 2021-07-11
  • 2021-10-28
  • 1970-01-01
  • 1970-01-01
  • 2017-06-04
  • 2019-03-25
相关资源
最近更新 更多