Running composer install in docker container

↘锁芯ラ 提交于 2019-12-10 10:19:41

问题


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

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

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.

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


回答1:


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

  • 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)



回答2:


You are mounting your local volume over your build directory so anything you built in '/var/www/website' will be mounted over by your local volume when the container runs.



来源:https://stackoverflow.com/questions/38816691/running-composer-install-in-docker-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!