docker-node
docker-node copied to clipboard
Failing to build an image with netlify
Environment
I'm testing in both my Mac and Gitpod
I need to build a docker image with netlify.
What's working
So far, the only Dockerfile configuration I got to work is:
FROM node:14.4.0
WORKDIR /app
RUN npm install -g npm
RUN npm install --global netlify-cli
COPY package.json package-lock.json .npmrc ./
RUN npm install
ENV PATH /app/node_modules/.bin:$PATH
CMD ["netlify", "dev"]
The Problem
But you may ask why do I need line RUN npm install -g npm? Because otherwise it won't work, it will give errors like:
gitpod /workspace/mytest/frontend $ time docker build -t no_npm_up .
Sending build context to Docker daemon 9.97MB
Step 1/7 : FROM node:14.4.0
---> dcda6cd5e439
Step 2/7 : WORKDIR /app
---> Using cache
---> 9f5e3f7bfcd0
Step 3/7 : RUN npm install --global netlify-cli
---> Running in 3efd5c611280
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
> [email protected] preinstall /usr/local/lib/node_modules/netlify-cli/node_modules/yarn
> :; (node ./preinstall.js > /dev/null 2>&1 || true)
/usr/local/bin/netlify -> /usr/local/lib/node_modules/netlify-cli/bin/run
/usr/local/bin/ntl -> /usr/local/lib/node_modules/netlify-cli/bin/run
> [email protected] postinstall /usr/local/lib/node_modules/netlify-cli/node_modules/esbuild
> node install.js
Trying to install "esbuild-linux-64" using npm
Failed to install "esbuild-linux-64" using npm: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/netlify-cli/node_modules/esbuild/esbuild-hd4qktqi34q'
Trying to download "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.8.52.tgz"
/usr/local/lib/node_modules/netlify-cli/node_modules/esbuild/install.js:203
throw e;
^
Error: EACCES: permission denied, open '/usr/local/lib/node_modules/netlify-cli/node_modules/esbuild/bin/esbuild'
at Object.openSync (fs.js:461:3)
at Object.writeFileSync (fs.js:1387:35)
at /usr/local/lib/node_modules/netlify-cli/node_modules/esbuild/install.js:66:8
at Generator.next (<anonymous>)
at fulfilled (/usr/local/lib/node_modules/netlify-cli/node_modules/esbuild/install.js:6:24)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
errno: -13,
syscall: 'open',
code: 'EACCES',
path: '/usr/local/lib/node_modules/netlify-cli/node_modules/esbuild/bin/esbuild'
}
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.1 (node_modules/netlify-cli/node_modules/rollup/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @netlify/traffic-mesh-agent-darwin-x64@^0.27.10 (node_modules/netlify-cli/node_modules/@netlify/traffic-mesh-agent/node_modules/@netlify/traffic-mesh-agent-darwin-x64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @netlify/[email protected]: wanted {"os":"darwin","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @netlify/traffic-mesh-agent-win32-x64@^0.27.10 (node_modules/netlify-cli/node_modules/@netlify/traffic-mesh-agent/node_modules/@netlify/traffic-mesh-agent-win32-x64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @netlify/[email protected]: wanted {"os":"win32","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN @octokit/[email protected] requires a peer of @octokit/core@>=3 but none is installed. You must install peer dependencies yourself.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-02-25T07_08_18_487Z-debug.log
The command '/bin/sh -c npm install --global netlify-cli' returned a non-zero code: 1
real 0m48.009s
user 0m0.098s
sys 0m0.085s
Investigating these errors brought me to the Docker-Node Best Practices, I've tried several combinations, all throwing similar errors as above, e.g.:
FROM node:14.4.0
WORKDIR /app
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin
USER node
RUN npm install --global netlify-cli
COPY package.json package-lock.json .npmrc ./
RUN npm install
ENV PATH /app/node_modules/.bin:$PATH
CMD ["netlify", "dev"]
will fail with:
Step 8/10 : RUN npm install
---> Running in 6bca659bcdb7
npm ERR! code ENOLOCAL
npm ERR! Could not install from "node_modules/react-virtual-grid/iscroll@github:zhm/iscroll#larger-scrollbars-with-pointer-events" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/node/.npm/_logs/2021-02-26T07_30_21_207Z-debug.log
The command '/bin/sh -c npm install' returned a non-zero code: 1
Or if I move the USER node down:
FROM node:14.4.0
WORKDIR /app
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin
RUN npm install --global netlify-cli
COPY package.json package-lock.json .npmrc ./
RUN npm install
ENV PATH /app/node_modules/.bin:$PATH
USER node
CMD ["netlify", "dev"]
will fail even earlier:
Step 5/10 : RUN npm install --global netlify-cli
---> Running in fb58883c6fc2
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
> [email protected] preinstall /home/node/.npm-global/lib/node_modules/netlify-cli/node_modules/yarn
> :; (node ./preinstall.js > /dev/null 2>&1 || true)
/home/node/.npm-global/bin/netlify -> /home/node/.npm-global/lib/node_modules/netlify-cli/bin/run
/home/node/.npm-global/bin/ntl -> /home/node/.npm-global/lib/node_modules/netlify-cli/bin/run
> [email protected] postinstall /home/node/.npm-global/lib/node_modules/netlify-cli/node_modules/esbuild
> node install.js
Trying to install "esbuild-linux-64" using npm
Failed to install "esbuild-linux-64" using npm: EACCES: permission denied, mkdir '/home/node/.npm-global/lib/node_modules/netlify-cli/node_modules/esbuild/esbuild-jofiarpavc'
Trying to download "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.8.52.tgz"
/home/node/.npm-global/lib/node_modules/netlify-cli/node_modules/esbuild/install.js:203
throw e;
^
Error: EACCES: permission denied, open '/home/node/.npm-global/lib/node_modules/netlify-cli/node_modules/esbuild/bin/esbuild'
at Object.openSync (fs.js:461:3)
at Object.writeFileSync (fs.js:1387:35)
at /home/node/.npm-global/lib/node_modules/netlify-cli/node_modules/esbuild/install.js:66:8
at Generator.next (<anonymous>)
at fulfilled (/home/node/.npm-global/lib/node_modules/netlify-cli/node_modules/esbuild/install.js:6:24)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
errno: -13,
syscall: 'open',
code: 'EACCES',
path: '/home/node/.npm-global/lib/node_modules/netlify-cli/node_modules/esbuild/bin/esbuild'
}
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.1 (node_modules/netlify-cli/node_modules/rollup/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @netlify/traffic-mesh-agent-win32-x64@^0.27.10 (node_modules/netlify-cli/node_modules/@netlify/traffic-mesh-agent/node_modules/@netlify/traffic-mesh-agent-win32-x64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @netlify/[email protected]: wanted {"os":"win32","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @netlify/traffic-mesh-agent-darwin-x64@^0.27.10 (node_modules/netlify-cli/node_modules/@netlify/traffic-mesh-agent/node_modules/@netlify/traffic-mesh-agent-darwin-x64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @netlify/[email protected]: wanted {"os":"darwin","arch":"x64"} (current: {"os":"linux","arch":"x64"})
npm WARN @octokit/[email protected] requires a peer of @octokit/core@>=3 but none is installed. You must install peer dependencies yourself.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-02-26T07_46_56_742Z-debug.log
The command '/bin/sh -c npm install --global netlify-cli' returned a non-zero code: 1
Question
So, why do I need line RUN npm install -g npm? I didn't need it until a week ago when I decided to update our image.
And what am I doing wrong about the "Best Practices"? Now I know about them, I want to use them.