Expected result

Would you please advise on how to install npm and composer dependencies in my webroot via the Dockerfile on a AWS Elasticbeanstalk Multi-Container Docker app?

Current situation

I've been building my files from within the docker container via the Dockerfile with code like this:

// Dockerfile

# npm
WORKDIR /var/www/tmp_html
RUN mkdir -p npm
WORKDIR /var/www/tmp_html/npm
COPY php-app/package.json package.json
RUN npm update && npm install

# composer
... // similar to above

# Switch working directory back to webroot
WORKDIR /var/www/html

After deployment, when I ssh into the instance's php:fpm container, i can see the following structure:

root@3f8bf1xc2a78:/var/www# ls
html  tmp_html

The built files are in /tmp_html and i'm trying to move them into /html. via my Dockerfile like this:

ONBUILD RUN mv -v ../tmp_html/composer/protected/vendor/* protected/vendor \
    && rm -rf ../tmp_html/composer/protected \
    && mv -v ../tmp_html/composer/* . \
    && mv -v ../tmp_html/npm/* . \
    && rm -rf ../tmp_html


Problem is, the ONBUILD step is not working. On Docker Inspect the php:fpm container, i noticed this: "OnBuild": null. It seems like the onbuild didn't even run. The files in the the /html and /tmp_html folders remain the same.

Furthermore, if i RUN the commands plainly without the ONBUILD command, on docker push to the docker image repository, the target location cannot be detected and refuses to let me push so i can't even deploy. The error is: mv: target 'protected/vendor' is not a directory I guess this is because elasticbeanstalk hasn't copied the bundle in, so at this point the html folder isn't even available.


Stop with the temporary directory. Copy the files into the image where you need them and then when building the image install your npm modules and your composer modules.

Not sure why you want to have them in temp folder then move them?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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