为什么我的卷没有复制到其Docker容器中?

时间:2019-04-05 00:24:32

标签: php laravel docker docker-compose docker-volume

我正在尝试使用nginx和运行Laravel应用程序的php-fpm服务器运行Web服务器容器。该目录包含一个前端和后端目录,因此在配置文件中不会关闭我的路径。

我设置了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 Web服务器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似乎与所发生的事情最相关,但我想我已经在接受公认的答案所建议的所有内容。

即使我通过卷安装文件夹,我是否仍需要包含COPYADD命令?

1 个答案:

答案 0 :(得分:0)

构建阶段看不到任何已安装的卷。唯一可用于“构建”的是backend.docker和build的compose部分中定义的事物:

    build:
      context: ./
      dockerfile: backend.docker
  

即使通过卷安装文件夹,我是否仍需要包括COPY或ADD命令?

是的,修改您的backend.docker与此类似

...
WORKDIR /var/www
ADD composer.json .
RUN composer install