4

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

4
  • 1
    It is likely the directory is created after the container starts running. Double check if the base image your container is using has the /var/www/website endpoint. You can try to do this by using a different entrypoint (such as /bin/bash) instead of the default entry point.
    – ffledgling
    Aug 7, 2016 at 17:26
  • I also believe this might indeed be the issue. The volumes code in the yml file attaches my project code to that folder, so running a composer update in the DockerFile will always be done before my actual code is present. What would be the correct way of calling composer then?
    – SnIpY
    Aug 7, 2016 at 17:31
  • @SnlpY comment out the Volume mounting code temporarily, or don't use docker-compose and directly run the docker image in docker/php to figure out what's going on?
    – ffledgling
    Aug 7, 2016 at 17:52
  • Docker volumes will create the target directory if it does not exist. Simply add a line to your Dockerfile to create the folder to fix it, i.e. RUN mkdir /var/www/website. Aug 7, 2016 at 17:59

2 Answers 2

4

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
  • Hi @Michal CMD at the end of dockerfile will exited the container with status 0. How to use the CMD then? May 20, 2019 at 6:41
  • @AlvinTheodora Hi, did you solve your problem? Not sure if I understood it as exit code 0 means the command was executed succesfully.
    – Michal
    Nov 25, 2019 at 12:09
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.