简体   繁体   中英

How to write and read file in docker using multer

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM