Setup
I'm trying to dockerize a pretty old project that uses Node 12, npm 8 and bower.
Since there's no prebuilt image that bundles these three dependencies, I'm building my own image with this Dockerfile
:
FROM node:12
RUN npm install -g npm@8
RUN npm install -g bower
RUN echo "node version: $(node --version)"
RUN echo "npm version: $(npm --version)"
RUN echo "bower version: $(bower --version)"
Here's the docker-compose.yml
(fragment):
version: "3.9"
services:
frontend:
build: ./front-end
working_dir: /home/node/app/
volumes:
- ./front-end:/home/node/app/
entrypoint: [ "/bin/bash", "-c" ]
command:
- |
npm i
bower i --allow-root
npm start
Problem
I run it like this:
docker compose build frontend --no-cache --progress=plain
docker compose up --force-recreate frontend
It crashes like this:
my-frontend-1 | npm ERR! path /home/node/app/node_modules/ember-cli-cookie
my-frontend-1 | npm ERR! command failed
my-frontend-1 | npm ERR! command sh -c -- bower install --allow-root
my-frontend-1 | npm ERR! /home/node/app/node_modules/bower/lib/node_modules/configstore/index.js:54
my-frontend-1 | npm ERR! throw err;
my-frontend-1 | npm ERR! ^
my-frontend-1 | npm ERR!
my-frontend-1 | npm ERR! Error: EACCES: permission denied, open '/root/.config/configstore/bower-github.json'
my-frontend-1 | npm ERR! You don't have access to this file.
Analysis
Here's my reconstruction of events:
- First of all, it's not the
bower i
step ofdocker-compose.yml
that's crashing, it'snpm i
. If I comment outnpm i
, then the script proceeds further. npm
installs theember-cli-cookie@0.2.0
package.npm
calls the postinstall script ofember-cli-cookie
.- The
postinstall
script callsbower install --allow-root
. - The actual command executed by
npm
issh -c -- bower install --allow-root
. - It crashes with
EACCES: permission denied, open '/root/.config/configstore/bower-github.json'
.
Here are permissions for the inaccessible file:
root@7d24854cf1af:/home/node/app# ls -alhF /root/.config/configstore/
total 20K
drwx------ 1 root root 4.0K Aug 24 20:16 ./
drwx------ 1 root root 4.0K Aug 24 19:55 ../
-rw------- 1 root root 2 Aug 24 20:16 bower-github.json
-rw------- 1 root root 55 Aug 24 19:55 update-notifier-npm.json
whoami
returns root
.
I checked permissions and username by inserting commands into docker-compose.yml
immediately before npm i
.
I don't understand how this can be possible: root is unable to access a file with permissions of -rw------- 1 root root
.
If I try accessing it manually like this (replicating the sh -c
approach):
sh -c -- "nano /root/.config/configstore/bower-github.json"
...I'm able to view the file save changes to it just fine.
I even tried adding RUN chmod -R a+rwx /root/.config/
to the end of my Dockerfile, rebuilding the image and recreating the container — it made no difference!
Question
Why is this happening and how to fix it?
PS Homework
I've found these related questions but their answers did not help me:
EACCES, permission denied when running bower — I don't have a
~/.cache
folder.bower install fails giving me EACCES: permission denied error — the user inside the container is
root
, the$USER
and$GROUP
env vars are empty.Error: EACCES: permission denied — the
~/.npm-global
approach did not help.whoami
isroot
already.⚠ Adding
--unsafe-perm=true --allow-root
tonpm i
resolves the issue,npm i
completes successfully, but thennpm start
crashes with exactly the same error (except the inaccessible file is/root/.config/configstore/ember-cli.json
), and adding those flags tonpm start
does not help.