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?
2
Answers
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.I finally updated my docker-compose.yml file like this:
This way, each time I edit something in a js or css file, everything gets automatically rebuild and minified by Symfony Encore/Webpack