Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix permission issue encountered on Docker hub
The first builds on docker hub all failed. The error we were getting was ``` [91m ERR! Error: EACCES: permission denied, open '/home/node/package.json' npm ERR! [Error: EACCES: permission denied, open '/home/node/package.json'] { npm ERR!�[0m [91m errno: -13, npm ERR! code: 'EACCES', npm �[0m [91mERR! syscall: 'open', npm ERR! path: '/home/node/package.json' ... �[91m The operation was rejected by your operating system. npm ERR! It is likely you do not have the permissions to access this file as the current user npm ERR!�[0m �[91m npm ERR! If you believe this might be a permissions issue, please double-check the npm ERR! permissions of the file and its containing directories, or try running npm ERR! the command again as root/Administrator. �[0m �[91m �[0m �[91mnpm ERR! A complete log of this run can be found in: npm ERR!�[0m �[91m /home/node/.npm/_logs/2021-02-18T09_51_29_644Z-debug.log �[0m Removing intermediate container 04acee56b734 The command '/bin/sh -c npm install' returned a non-zero code: 243 ``` Some searching of the net indicated that the problem is because the `node` user that is provided in the base image and which we set as the main user does not own the `package.json` files we copy into the image. It's best practise not to leave the user as `root` in a Docker image, nor to run `npm install` as `root`. We now understand the reason the `node` user is not the owner of the files is because all `COPY` commands in a Dockerfile are carried out as the `root` user. The suggested fix is to include [chown](https://en.wikipedia.org/wiki/Chown) within your copy statement to ensure once the files are available the non-root user is made the owner. - nodejs/docker-node#1262 (comment) - https://stackoverflow.com/a/44766666/6117745
- Loading branch information