So, I updated npm inside docker container and since I have node version 6.9.4, npm is broken. Any npm commands will throw this error.
client | module.js:471
client | throw err;
client | ^
client |
client | Error: Cannot find module 'process-nextick-args'
client | at Function.Module._resolveFilename (module.js:469:15)
client | at Function.Module._load (module.js:417:25)
client | at Module.require (module.js:497:17)
client | at require (internal/module.js:20:19)
client | at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js:26:23)
client | at Module._compile (module.js:570:32)
client | at Object.Module._extensions..js (module.js:579:10)
client | at Module.load (module.js:487:32)
client | at tryModuleLoad (module.js:446:12)
client | at Function.Module._load (module.js:438:3)
and I would like to downgrade npm to 3.10.10.
Is there any way to do this without recreating the container?
I'm using docker-compose.
Related
I study containers. For it, I implement it in a particular project, available on this link. When I type the command docker-compose up, an error log below pops out. I can run the command npm start without problems.
Attaching to nodejs
nodejs | [nodemon] 2.0.15
nodejs | [nodemon] to restart at any time, enter `rs`
nodejs | [nodemon] watching path(s): *.*
nodejs | [nodemon] watching extensions: js,mjs,json
nodejs | [nodemon] starting `node app.js ./src/index.js`
nodejs | /home/node/app/src/index.js:2
nodejs | import express from 'express';
nodejs | ^^^^^^^
nodejs |
nodejs | SyntaxError: Unexpected identifier
nodejs | at Module._compile (internal/modules/cjs/loader.js:723:23)
nodejs | at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
nodejs | at Module.load (internal/modules/cjs/loader.js:653:32)
nodejs | at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
nodejs | at Function.Module._load (internal/modules/cjs/loader.js:585:3)
nodejs | at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
nodejs | at startup (internal/bootstrap/node.js:283:19)
nodejs | at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
nodejs | [nodemon] app crashed - waiting for file changes before starting...
I am dockerizing a system that uses a pem and key to authenticate with a remote dev server. Unfortunately, it would appear that it is unable to find the file despite it being in the docker image.
Error
server_1 | Error: ENOENT: no such file or directory, open '/app/certificates/jwt.key'
server_1 | at Object.openSync (fs.js:497:3)
server_1 | at Object.readFileSync (fs.js:393:35)
server_1 | at Object.<anonymous> (/app/controllers/user.js:7:16)
server_1 | at Module._compile (internal/modules/cjs/loader.js:1085:14)
server_1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
server_1 | at Module.load (internal/modules/cjs/loader.js:950:32)
server_1 | at Function.Module._load (internal/modules/cjs/loader.js:790:12)
server_1 | at Module.require (internal/modules/cjs/loader.js:974:19)
server_1 | at require (internal/modules/cjs/helpers.js:101:18)
server_1 | at Object.<anonymous> (/app/routes/upload.js:8:24)
server_1 | at Module._compile (internal/modules/cjs/loader.js:1085:14)
server_1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
server_1 | at Module.load (internal/modules/cjs/loader.js:950:32)
server_1 | at Function.Module._load (internal/modules/cjs/loader.js:790:12)
server_1 | at Module.require (internal/modules/cjs/loader.js:974:19)
server_1 | at require (internal/modules/cjs/helpers.js:101:18) {
server_1 | errno: -2,
server_1 | syscall: 'open',
server_1 | code: 'ENOENT',
server_1 | path: '/app/certificates/jwt.key'
server_1 | }
Line (server/controllers/user.js -> app/controllers/user.js)
const pem = fs.readFileSync(path.resolve(__dirname, "../certificates/jwt.key"));
Dockerfile
FROM node:14
RUN mkdir app
WORKDIR /app
COPY . .
RUN npm install
RUN npm run get_key
EXPOSE 5000
CMD [ "npm", "run", "start" ]
package.json
"scripts": {
"test": "mocha -r dotenv/config ./**/*.test.js",
"start": "node -r dotenv/config server.js",
"dev": "nodemon -r dotenv/config server.js",
"get_key": "ssh-keygen -t rsa -b 4096 -m PEM -f ./certificates/jwt.key -P ''"
},
The volume mount was overriding the key building. Need to generate the key locally first before composing.
server:
build: server
ports:
- "5000:5000"
restart: always
depends_on:
- mongodb
volumes:
- ./server:/app
I recently ran npm install and npm update.
Then I tried to build my docker container. I keep getting the same stacktrace:
Step 7/8 : RUN npm run build
---> Running in 9d7f766e2cf7
> docs.rpg.riotgames.io#1.0.0 build /riot/rpg-docs-hub
> next build
(node:18) ExperimentalWarning: The fs.promises API is experimental
Loaded env from /riot/rpg-docs-hub/.env
> Build error occurred
{ Error: Cannot find module './src'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/riot/rpg-docs-hub/node_modules/dotenv-webpack/index.js:9:14)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (/riot/rpg-docs-hub/next.config.js:4:16)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32) code: 'MODULE_NOT_FOUND' }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! docs.rpg.riotgames.io#1.0.0 build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the docs.rpg.riotgames.io#1.0.0 build 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-03T19_16_10_771Z-debug.log
ERROR: Service 'rpg-docs-hub' failed to build : The command '/bin/sh -c npm run build' returned a non-zero code: 1
I tried...
repeating npm install and npm update
Running docker-compose up --build
running npm install --save-dev dotenv-webpack, since this seems to be associated with webpack
The result is the same.
My level of technical understanding is limited, though I'm trying to ramp up quickly.
Any help is appreciated. thanks!
I'm using alpine-openjdk image with s6-overlay for running services on docker. I'm trying to run ganache-cli on the same image, either as another service or as an initialization script, but couldn't get it to work. Is there an example of running ganache-cli with s6-overlay?
Thanks.
Here's what my DockerFile looks like:
FROM smebberson/alpine-openjdk
RUN apk update && apk add nodejs
RUN npm install -g ganache-cli
ADD etc /etc
EXPOSE 8081
ENTRYPOINT ["/init"]
Running ganache-cli & in cont-init.d
Getting the following error when running the image:
/usr/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:52
*/var n=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable;e.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;r<10;r++)t["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach(function(e){n[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(e){return!1}}()?Object.assign:function(e,t){for(var r,o,c=function(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}(e),s=1;s<arguments.length;s++){for(var f in r=Object(arguments[s]))a.call(r,f)&&(c[f]=r[f]);if(n){o=n(r);for(var d=0;d<o.length;d++)i.call(r,o[d])&&(c[o[d]]=r[o[d]])}}return c}},function(e,t){e.exports=function(e,t,r){var n=t.
SyntaxError: Unexpected identifier
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:528:28)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/lib/node_modules/ganache-cli/cli.js:12:13)
at Module._compile (module.js:556:32)
As title, I am using docker ruby 2.3.5 (ubuntu) environment, despite I have already setup NODE_ENV=development, when I try to intercept the value of process.env.NODE_ENV I still see production, which I can't find anywhere it has been overridden. It only happens in the docker environment but not on my MacOS, not sure whats the reason?
Update: Here is Dockerfile and docker-compose.yml for reference:
https://gist.github.com/goodwill/b4e677ccf8fe0079183adeec35218812
Update: This is the error I end up with when running webpacker-dev-server:
04:08:37 webpacker.1 | /app/config/webpack/development.js:20
04:08:37 webpacker.1 | https: settings.dev_server.https,
04:08:37 webpacker.1 | ^
04:08:37 webpacker.1 |
04:08:37 webpacker.1 | TypeError: Cannot read property 'https' of undefined
04:08:37 webpacker.1 | at Object.<anonymous> (/app/config/webpack/development.js:20:31)
04:08:37 webpacker.1 | at Module._compile (module.js:570:32)
04:08:37 webpacker.1 | at Object.Module._extensions..js (module.js:579:10)
04:08:37 webpacker.1 | at Module.load (module.js:487:32)
04:08:37 webpacker.1 | at tryModuleLoad (module.js:446:12)
04:08:37 webpacker.1 | at Function.Module._load (module.js:438:3)
04:08:37 webpacker.1 | at Module.require (module.js:497:17)
04:08:37 webpacker.1 | at require (internal/module.js:20:19)
04:08:37 webpacker.1 | at requireConfig (/app/node_modules/webpack/bin/convert-argv.js:97:18)
04:08:37 webpacker.1 | at /app/node_modules/webpack/bin/convert-argv.js:104:17
Docker containers will not collect environment variables from your local environment.
Set the environmental variable inside your Dockerfile. For example:
ENV NODE_ENV=development
Alternatively, you can run the container with that environmental variable from the command line:
$ docker run -e NODE_ENV=devlopment mycontainer