What are the steps to resolving a Dockerfile error regarding permission denied for /app?

Here is the Dockerfile for my node.js project:

FROM node:14.16.0-alpine3.13

RUN addgroup app && adduser -S -G app app
RUN mkdir /app && chown app:app /app
USER app

WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .

EXPOSE 80

CMD ["npm", "start"]

After giving relevant access to the app, I encountered an error when running docker-compose up on my Ubuntu 18 server:

Step 6/9 : RUN npm install
 ---> Running in d95487caef6b
npm WARN checkPermissions Missing write access to /app
npm WARN <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6d1803040504400f0c0e060803092d5c435d435d">[email protected]</a> No description
npm WARN <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="71041f1819185c1310121a191415244949525252635e414f514f4d48">[email protected]</a> No repository field.

npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /app
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/app'
npm ERR!  [Error: EACCES: permission denied, access '/app'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/app'
npm ERR! }
npm ERR!
npm ERR! 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!
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/app/.npm/_logs/2021-11-10T10_53_06_750Z-debug.log
The command '/bin/sh -c npm install' returned a non-zero code: 243
ERROR: Service 'api' failed to build : Build failed

Note: My app service name is 'api'.

It's worth mentioning that this project works fine on my local Windows system with the same Dockerfile.

Answer №1

Through my experimentation, I discovered that rather than utilizing the following commands:

$ docker-compose build
$ docker-compose up -d

The correct approach is to use docker-compose up -d --build in order for it to function properly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

execute numerous queries simultaneously

I have a task of creating a bridge (script) that connects two databases, Mongo and Oracle. First, I execute three find queries on my MONGO database from three different collections: Collection 1 = [{ name: 'Toto', from: 'Momo', ...

Developing a seamless social authentication process using react-native in tandem with a backend API

I'm currently working on developing a mobile app using React Native along with a NodeJS/MongoDB API Backend. One of the key features I want to integrate is social authentication through Google/Facebook, but it's crucial for this process to occur ...

What causes the 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR' error in a Node.js and Express application?

Trying my hand at building an application using Node and Express has been smooth sailing until today when I encountered this error: { code: "PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR", fatal: false } According to Google, I should switch from create ...

Reasons why the Express Route fails to store cache while executed in a separate file

My code works fine when it's all in one file, but the caching stops working when I move it to a separate middleware file. Can someone help me understand why the caching isn't functioning properly in my middleware? Here is the working code: var e ...

Steps for launching Angular 5 application using Node.js server

I have developed an Angular 5 application that retrieves data from a node.js server. I successfully deployed the application to my web server hosted by FastComet, which supports node.js, but unfortunately, the server does not seem to be functioning properl ...

When converting to TypeScript, the error 'express.Router() is not defined' may

Currently, I am in the process of converting my express nodejs project from JavaScript to TypeScript. One of the changes I've made is renaming the file extension and updating 'var' to 'import' for "require()". However, there seems ...

ReactJS: Error - ReferenceError: React is not defined (no-undef)

I recently started learning React by following the tutorial on reactjs.org. After setting up my project using npm and creating my index.js file, I encountered an error: src\App.js Line 9:21: 'React' is not defined no-undef Line 42: ...

Sending an HTML form data to a Node.js server

I'm currently working on a simple project that involves creating a web form and sending it to node.js in order to save the information received. I've been following some YouTube tutorials (https://www.youtube.com/watch?v=rin7gb9kdpk), but I' ...

What are some alternative ways to link a local MongoDB database to my Android Studio application instead of using MongoLab?

Can someone please help me figure out how to connect my Android Studio project to a MongoDB database stored locally on my PC? I've been searching for solutions that don't involve using MLab, but I haven't had any luck. I've attempted f ...

Error: The call stack has reached its maximum size while running an npm install

Attempting to execute npm install, encountered the following console output: npm ERR! Linux 4.8.0-27-generic npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" npm ERR! node v6.9.1 npm ERR! npm v3.10.8 npm ERR! Maximum call stack size exceeded npm ...

How can I include npm package js and css files in Vue CLI with webpack?

I am currently attempting to integrate an npm package into my vue-cli development site. The instructions provided by the package website are as follows: https://i.stack.imgur.com/R2Inl.png The instructions state that both the css and js files need to be ...

Do potential version conflicts arise between Node.js, npm, and Sails.js?

I went through the following steps to create my very first sailsjs MVC application: sudo apt-get install nodejs nodejs -v shows v0.10.25 sudo apt-get install npm npm -v shows 1.3.10 sudo npm install -g sails Following those steps, I encountered the fo ...

The elusive nodemailer greeting remains unacknowledged on its own SMTP server

I am currently working on setting up an email system using nodemailer with a company-owned SMTP server. Here is my code snippet: Const transporter = nodemailer.createTransport({ host : smtp.example.com, Port:25, Tls: { rejectUnauthorized: false} }); ...

Using TypeORM with a timestamp type column set to default null can lead to an endless loop of migrations being

In my NestJs project using TypeORM, I have the following column definition in an entity: @CreateDateColumn({ nullable: true, type: 'timestamp', default: () => 'NULL', }) public succeededAt?: Date; A migration is gene ...

Harnessing the power of helper classes effortlessly within expressjs

I've been working on a basic expressjs application and I'm hoping to incorporate a new library or helper to organize some of my code. My goal is for this library to function as a module, but unfortunately, I'm encountering difficulties in ge ...

Press the key to navigate to a different page

I have an input field for a search box. I want it so that when I enter my search query and press enter, the page navigates to another page with the value of the input included in the URL as a query string. How can I achieve this functionality? Thank you ...

Value as a String inside an Object

I am encountering an issue with using the obj to store string values in my project. The strings contain commas, and for some reason, it is not working as expected. const resizedUrl ={ 'mobile': "'images','400x/images' ...

Guide to launching Cardano Wallet

After following the steps in this guide, I have successfully installed cardano-wallet. However, I am unsure how to run it and interact with it using node js: const { WalletServer } = require('cardano-wallet-js'); let walletServer = WalletServer. ...

Leveraging webpack for loading images in a React application

I am encountering an issue with loading images after deploying to the server. I am unsure of the cause, but only a few images seem to render properly when using npm. Upon analysis: https://i.stack.imgur.com/ICgCN.png If the images load correctly with a ...

Tips for incorporating the "define" function into your Mocha testing

Starting my journey with JavaScript testing, I made the decision to use Mocha. The specific modules I am looking to test are AMD/RequireJS. However, it appears that Mocha only works with CommonJS modules. Consequently, when trying to run it, I encounter t ...