0

I'm using multer to save upload file to specific directory. I'ts working perfect in local, but when I build using docker, the multer isn't write the file in my folder.

this is my multer code :

const storage = multer.diskStorage({
  destination: (req, file, cb) => {
    cb(null, __basedir + "/uploads/")
  },
  filename: (req, file, cb) => {
    cb(null, file.originalname)
  }
})

and i decided to using volumes in docker-compose like this :

volumes:
      - ./uploads:/app/uploads

and error Error: EACCES: permission denied, open '/app/uploads/Funder Statement Test data.xlsx'

this is my dockerFile :

FROM node:fermium-alpine

RUN apk add --no-cache \
      chromium \
      nss \
      freetype \
      harfbuzz \
      ca-certificates \
      ttf-freefont \
      nodejs \
      yarn

# Tell Puppeteer to skip installing Chrome. We'll be using the installed package.
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
    PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser

# Puppeteer v10.0.0 works with Chromium 92.
RUN yarn add puppeteer@10.0.0

# Add user so we don't need --no-sandbox.
RUN addgroup -S pptruser && adduser -S -G pptruser pptruser \
    && mkdir -p /home/pptruser/Downloads /app \
    && chown -R pptruser:pptruser /home/pptruser \
    && chown -R pptruser:pptruser /app 

# Run everything after as non-privileged user.
USER pptruser

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 3030

CMD ["npm", "start"]


Any idea how to solve my error ?

  • Which Docker image is used? – Kevin Wittek Mar 28 '22 at 07:39
  • The most likely case is the host and container user IDs not matching; see [Docker-compose set user and group on mounted volume](https://stackoverflow.com/questions/40462189/docker-compose-set-user-and-group-on-mounted-volume). – David Maze Mar 28 '22 at 10:42

1 Answers1

0

The user under which the Docker container is running likely has no permission to write into the mapped folder ./uploads. Make sure, the permissions are correct.

Kevin Wittek
  • 1,369
  • 9
  • 26
  • i updated my code with dockerFile. I think the multer cant write because dont have access to write. Can you give me example how to give the permission on my dockerFile ? – user18605090 Mar 28 '22 at 07:56
  • The problem is `USER pptruser`, this means it will be a user that likely has a different UID than your host user. Depending on your use case, using the `root` user inside the image would work around this. – Kevin Wittek Mar 29 '22 at 12:07