I'm running a docker container with PHP and node installed through nvm. A Symfony 6 app is mounted into it.
I'd like to user Symfony 6's "Encore" tool to compile my assets.
I connect to my container like this:
sudo docker exec -ti 860cb4e01268 bash
And then I move to the directory when my symfony app is mounted.
Typing npm run build
returns the following message /usr/bin/env: 'node': Permission denied
Node is installed and $PATH seems correct, when I type node
, I can enter the node console as expected. Same thing if I type /usr/bin/env: node
.
Still from inside the container, a whoami
returns "root", so I don't get how I could have a permission issue.
Finally, if I directly run node node_modules/@symfony/webpack-encore/bin/encore.js prod
, it works and builds my asset as expected.
I don't get why a simple npm run build
won't work?
CodePudding user response:
Instead of installing node through nvm, I installed it like suggested here https://askubuntu.com/questions/720784/how-to-install-latest-node-inside-a-docker-container. A npm run build
now works as expected.
CodePudding user response:
I finally updated my docker-compose.yml file like this:
nodejs:
image: node:16.16.0
working_dir: /website
command: npm run watch
volumes:
- /home/path-to-my-website-files-on-host-machine:/website
ports:
- 8888:8888
This way, each time I edit something in a js or css file, everything gets automatically rebuild and minified by Symfony Encore/Webpack