【发布时间】:2019-04-05 00:24:32
【问题描述】:
我正在尝试使用 nginx 和运行 Laravel 应用程序的 php-fpm 服务器运行 webserver 容器。该目录包含一个前端和后端目录,因此我的路径在配置文件中没有关闭。
我设置了一个 docker-compose.yml 文件
version: '2'
services:
webserver:
build:
context: ./
dockerfile: webserver.docker
volumes:
- /home/colesam/Documents/code/todo/backend:/var/www
ports:
- "8080:80"
links:
- backend
backend:
build:
context: ./
dockerfile: backend.docker
volumes:
- ./home/colesam/Documents/code/todo/backend:/var/www
和 php-fpm Dockerfile (backend.docker)
FROM php:7.2-fpm
RUN apt-get update -y && apt-get install -y libmcrypt-dev openssl
RUN pecl install mcrypt-1.0.2
RUN docker-php-ext-enable mcrypt
RUN docker-php-ext-install pdo mbstring
RUN apt-get install -y apt-transport-https
RUN apt-get install -y curl
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN chown -R www-data:www-data /var/www
VOLUME ["/var/www"]
RUN ls -al /var/www
WORKDIR /var/www
RUN composer install
和nginx webserver Dockerfile (webserver.docker)
FROM nginx:1.10
ADD ./vhost.conf /etc/nginx/conf.d/default.conf
WORKDIR /var/www
由于某种原因,当我运行 docker-compose up -d --build 时,我总是在构建过程的这一步失败:
Step 13/13 : RUN composer install
---> Running in 65bb97f03004
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Composer could not find a composer.json file in /var/www
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
ERROR: Service 'backend' failed to build: The command '/bin/sh -c composer install' returned a non-zero code: 1
从输出的最后一行看来它失败了,因为 /var/www/ 是空的并且没有像 composer.json 那样复制文件。我环顾四周,这个stackoverflow issue 似乎与正在发生的事情最相关,但我认为我已经在遵循公认答案所暗示的一切。
即使我通过卷安装文件夹,是否也需要包含COPY 或ADD 命令?
【问题讨论】:
-
Dockerfile 中的任何内容都不会看到卷。
-
您的网络服务器和后端的主机卷路径不同。
-
可能会删除“。”在此声明中:“volumes: - ./home/colesam/Documents/code/todo/backend:/var/www”
标签: php laravel docker docker-compose docker-volume