I wonder if upgrading npm and nodejs is what got it working. Here is what I did (as root rather than entering the workspace container with --user=laradock
):
cd /apps/laradock/ && docker-compose exec workspace bash
apt-get update
apt-get install -y npm
curl -sL https://deb.nodesource.com/setup_10.x | bash -
apt-get install -y nodejs
(from https://stackoverflow.com/a/34558299/470749 and https://askubuntu.com/a/1044694/48214)
Now this works: docker exec -it laradock_workspace_1 /bin/sh -c "cd /var/www/myapp/ && npm run production"
It would be great if I could get this similar question working too: How to use Deployer with Docker (Laradock)
P.S. Now outside the container, npm -v
shows "6.2.0" and nodejs -v
shows "v4.2.6" while inside container: npm -v
shows "6.4.0" and nodejs -v
shows "v10.9.0" and nvm --version
shows "0.33.8".
I'm still not sure how to get this to install properly in the Laradock Dockerfile. Its default way of installing nvm and npm doesn't seem to expose them to commands from outside the container such as docker exec -it laradock_workspace_1 /bin/bash -c "npm -v"
.
Update 12 months later
I added this near the bottom of my Dockerfile (adding it sooner caused errors), and it seems to work:
RUN apt update && \
apt install -y npm nodejs
#https://stackoverflow.com/a/26320915/470749
RUN ln -s /usr/bin/nodejs /usr/bin/node
RUN npm --version && node --version
RUN npm cache clean -f && \
npm install npm@latest -g n && \
#npm install -g n && \
n stable && \
npm --version && node --version