在docker容器中运行composer安装 [英] Running composer install in docker container

查看:638
本文介绍了在docker容器中运行composer安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个docker-compose.yml脚本,如下所示:

I have a docker-compose.yml script which looks like this:

version: '2'
services:
  php:
    build: ./docker/php
  volumes:
    - .:/var/www/website

位于./docker/php中的DockerFile看起来像这样:

The DockerFile located in ./docker/php looks like this:

FROM php:fpm

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
RUN mv composer.phar /usr/local/bin/composer
RUN composer update -d /var/www/website

事件总是失败,并显示错误

Eventho this always fails with the error

[RuntimeException]
Invalid working directory specified, /var/www/website does not exist.

当我删除RUN composer更新行并输入容器时,该目录确实存在并且包含我的项目代码。

When I remove the RUN composer update line and enter the container, the directory does exist and contains my project code.

请告诉我我做错了什么还是在错误的地方进行作曲家更新

Please tell me if I am doing anything wrong OR if I'm doing the composer update on a wrong place

推荐答案

RUN ... 行在构建映像时运行。
卷已连接到容器。您在这里至少有两个选择:

RUN ... lines are run when the image is being built. Volumes are attached to the container. You have at least two options here:


  • 使用 COPY 命令,将您的应用程序代码复制到该映像,以便该命令之后的所有命令都可以访问它。 (不要将映像推送到任何公共Docker存储库,因为它会包含您可能不想泄漏的源代码)

  • 在容器上运行命令来安装composer依赖项( CMD 或Dockerfile中的 ENTRYPOINT 或docker-compose中的 command 选项)

  • use COPY command to, well, copy your app code to the image so that all commands after that command will have access to it. (Do not push the image to any public Docker repo as it will contain your source that you probably don't want to leak)
  • install composer dependencies with command run on your container (CMD or ENTRYPOINT in Dockerfile or command option in docker-compose)

这篇关于在docker容器中运行composer安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆