I am trying to upload images files to a folder (/public/temp_upload) under the server root. The server was written by Node.js and uploading files are done by multer. It works fine on local but when the server is moved to a docker container, it throws a permission error.
Here is the code snippet. The error occurs in put endpoint.
const storage = multer.diskStorage({
    destination: (req, file, cb) => {
        cb(null, process.env.NODE_ENV === 'production' ? '/usr/src/app/public/temp_upload' : 'public/temp_upload');
    },
    filename: (req, file, cb) => {
        cb(null, Date.now() + '-' + file.originalname);
    },
});
const imageFilter = function(req, file, cb) {
    // accept image only
    if (!file.originalname.match(/\.(jpg|jpeg|png|gif)$/)) {
        return cb(new Error('Only image files are allowed!'), false);
    }
    cb(null, true);
};
const upload = multer({storage: storage, fileFilter: imageFilter});
module.exports = app => {
    app.post('/', async (req, res) => {
        const key = nanoid();
        console.log(req.body.type);
        const fileType = req.body.type.replace('image/', '');
        res.json({
            key,
            url:
                process.env.NODE_ENV === 'production'
                    ? `/usr/src/app/public/upload/${req.user.id}_${key}.${fileType}`
                    : `public/upload/${req.user.id}_${key}.${fileType}`,
        }).end();
    });
    app.put('/', upload.single('image'), async (req, res) => {
        res.status(200).json({tempPath: req.file.path});
    });
};
The error is
 image/jpeg
app_1    | [Error: EACCES: permission denied, open '/usr/src/app/public/temp_upload/1584467058084-3DkRrcPOfnF4pnEWRWyRu.jpg'] {
app_1    |   errno: -13,
app_1    |   code: 'EACCES',
app_1    |   syscall: 'open',
app_1    |   path: '/usr/src/app/public/temp_upload/1584467058084-3DkRrcPOfnF4pnEWRWyRu.jpg',
app_1    |   storageErrors: []
app_1    | }``