skip to Main Content

I am trying to upgrade my docker image from php:7.4-fpm-alpine3.13 to php:7.4-fpm-alpine3.14, in which this issue happened.

Error: EACCES: permission denied, open '/var/www/app/public/mix-manifest.json'

Dev team is currently use Laravel Mix to generate static files.

Logs:

/var/www/app # npm run development

> development
> mix

glob error [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
  errno: -13,
  code: 'EACCES',
  syscall: 'scandir',
  path: '/root/.npm/_logs'
}
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating

● Mix █████████████████████████ sealing (92%) asset processing SourceMapDevToolPlugin
 attached SourceMap

internal/fs/utils.js:332
    throw err;
    ^

Error: EACCES: permission denied, open '/var/www/app/public/mix-manifest.json'
    at Object.openSync (fs.js:497:3)
    at Object.writeFileSync (fs.js:1528:35)
    at File.write (/var/www/app/node_modules/laravel-mix/src/File.js:211:12)
    at Manifest.refresh (/var/www/app/node_modules/laravel-mix/src/Manifest.js:75:50)
    at /var/www/app/node_modules/laravel-mix/src/webpackPlugins/ManifestPlugin.js:21:48
    at Hook.eval [as callAsync] (eval at create (/var/www/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:12:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/var/www/app/node_modules/tapable/lib/Hook.js:18:14)
    at Compiler.emitAssets (/var/www/app/node_modules/webpack/lib/Compiler.js:850:19)
    at /var/www/app/node_modules/webpack/lib/Compiler.js:438:10
    at processTicksAndRejections (internal/process/task_queues.js:77:11) {
  errno: -13,
  syscall: 'open',
  code: 'EACCES',
  path: '/var/www/app/public/mix-manifest.json'
}

My dockerfile:

FROM php:7.4-fpm-alpine3.14

ARG COMPONENT
ARG APP_ENV
ARG SRC_DIR

# Update & add nginx
RUN apk update && 
    apk add nginx && mkdir -p /var/cache/nginx/ && 
    chmod 777 -R /var/lib/nginx/tmp
COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf
COPY ./docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf

# Give permission to nginx folder
RUN chown -R www-data:www-data /var/lib/nginx
RUN chmod 755 /var/lib/nginx/tmp/

# Add php.ini
COPY ./docker/${COMPONENT}/php.ini /etc/php7/php.ini

# Add entrypoint
COPY ./docker/${COMPONENT}/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

# Install nodejs, npm
RUN apk add --no-cache nodejs npm

# Create source code directory within container
RUN mkdir -p /var/www/app
RUN chown -R www-data:www-data /var/www/app

# Add source code from local to container
WORKDIR /var/www/app
COPY ${SRC_DIR} .

# Grant permission for folders & install packages
RUN chmod 777 -R bootstrap storage && 
    cp ./env/.env.${APP_ENV} .env && 
    composer install

RUN rm -rf .env
RUN npm install && npm run ${APP_ENV} && rm -rf node_modules

# Expose webserver ports
EXPOSE 80 443

# Command-line to run supervisord
CMD [ "/bin/bash", "/usr/local/bin/entrypoint.sh" ]

What I have tried:

  • rm -rf ./node_modules and install again
  • npm config set unsafe-perm true before running npm
  • RUN npm config set user 0 && npm config set unsafe-perm true before npm install

Any help is appreciated!

3

Answers


  1. Chosen as BEST ANSWER

    After almost a year later, I am facing my nemesis once again, and this time I told myself that I would resolve this issue once and for all. And for whom facing this issue in the future, this is what you need to run Laravel-Mix with Nodejs on an Alpine Image

    There are 2 options:

    #1 If you are stubborn, run it with an unofficial image of nodejs 14 built from musl instead of official provided package from Alpine Repository. Then extract and add executables (node14.4.0 and npm6.14.5) to PATH

    FROM php:8-fpm-alpine3.15
    ARG SRC_DIR
    ...
    # setting up packages bla bla
    ...
    
    # Install nodejs 14 from unofficial repo instead of
    # This will not work RUN apk add --no-cache nodejs npm
    RUN wget https://unofficial-builds.nodejs.org/download/release/v14.4.0/node-v14.4.0-linux-x64-musl.tar.xz -P /opt/
    RUN tar -xf /opt/node-v14.4.0-linux-x64-musl.tar.xz -C /opt/
    ENV PATH="$PATH:/opt/node-v14.4.0-linux-x64-musl/bin"
    ...
    
    WORKDIR /var/www/app
    COPY ${SRC_DIR} .
    ...
    RUN npm install 
    # Generating static
    RUN npm run dev
    ...
    

    #2 Using multistage build to build static with a fixed version of node instead of installing node on php alpine image (this was hint by my supervisor, which I did not understand why I was never thinking of before, silly me)

    FROM node:14-alpine AS node_builder
    ARG SRC_DIR
    
    RUN mkdir -p /var/www/mix
    WORKDIR /var/www/mix
    
    COPY ${SRC_DIR} ./
    
    # Installs all node packages
    RUN npm install 
    # Generating static into /var/www/mix
    RUN npm run dev
    
    FROM php:8-fpm-alpine3.15 as php_final
    ...
    # setting up packages bla bla
    ...
    WORKDIR /var/www/app
    COPY ${SRC_DIR} .
    
    COPY --from=node_builder /var/www/mix/public ./public/
    ...
    

  2. To who may also meet this issue, I re-installed nodejs in my CentOS 7 environment and solved the issue. The nodejs version is also same as the previous one (v14.18.1).

    Login or Signup to reply.
  3. my folder owner was root
    change of ownership helped

    chown admin:admin public -R

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search