在docker容器中运行composer安装

编程入门 行业动态 更新时间:2024-10-11 23:26:59
本文介绍了在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('getcomposer/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安装

本文发布于:2023-10-29 00:19:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538180.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:容器   docker   composer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!