Why I get error when try build image in docker?

agam theos

I want to make an image in docker. My app run in nodejs and use Mysql. When I build, it's error like this

[email protected] start /todo-skyshi
#11 1.831 > node server.js
#11 1.831
#11 2.247 /todo-skyshi/config/database/dbConn.js:4
#11 2.247 const db = new Sequelize(DB_NAME, DB_USERNAME,DB_PASSWORD, {
#11 2.247                          ^
#11 2.247
#11 2.247 ReferenceError: DB_NAME is not defined
#11 2.247     at Object.<anonymous> (/todo-skyshi/config/database/dbConn.js:4:26)
#11 2.247     at Module._compile (internal/modules/cjs/loader.js:999:30)
#11 2.247     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
#11 2.247     at Module.load (internal/modules/cjs/loader.js:863:32)
#11 2.247     at Function.Module._load (internal/modules/cjs/loader.js:708:14)
#11 2.247     at Module.require (internal/modules/cjs/loader.js:887:19)
#11 2.247     at require (internal/modules/cjs/helpers.js:74:18)
#11 2.247     at Object.<anonymous> (/todo-skyshi/config/model/activity.js:2:12)
#11 2.247     at Module._compile (internal/modules/cjs/loader.js:999:30)
#11 2.247     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
#11 2.261 npm ERR! code ELIFECYCLE
#11 2.264 npm ERR! errno 1
#11 2.271 npm ERR! [email protected] start: `node server.js`
#11 2.271 npm ERR! Exit status 1
#11 2.271 npm ERR!
#11 2.271 npm ERR! Failed at the [email protected] start script.
#11 2.272 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#11 2.336
#11 2.337 npm ERR! A complete log of this run can be found in:
#11 2.337 npm ERR!     /root/.npm/_logs/2022-02-13T02_20_56_653Z-debug.log
------
executor failed running [npm start]: exit code: 1

It's like the env on my DB params, how to build image in docker that can read env when I want to run with this command ?

docker run -e MYSQL_HOST=172.17.0.1 -e MYSQL_USER=xxxx -e MYSQL_PASWORD=xxxx -e MYSQL_DBNAME=todo -p 8090:3030 agamtheos/todo-skyshi

this is my Dockerfile :

FROM node:12-alpine

RUN apk update

RUN mkdir /todo-skyshi
ADD . /todo-skyshi
WORKDIR /todo-skyshi

RUN npm update
RUN ["npm", "start"]

Appreciate for any answer

Sandeep Patel

ReferenceError: DB_NAME is not defined #11 2.247 at Object. (/todo-skyshi/config/database/dbConn.js:4:26).

Abobe error clearly says that variables you are trying to access are not defined.

Env variables name passed in docker run command are different than used in code. DB_NAME, DB_USERNAME,DB_PASSWORD. For example

DB_NAME can be accessed as process.env.MYSQL_DBNAME and so other env variables.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why i get build error when i try to open my android studio project?

I get the error when i try get 50% of the image with cropperJS

Why I get error when I try to declare local variable?

Why I get error when I try to create stored procedure?

Why do I get an error for "__CrtGetFileInformationByHandleEx " when I try to compile

Why I get error when I try to install pyaudio?

Why I get an error when I try to upload a picture

I try to build Follow system, I have error when i try to get the pk of the vested account

Why I get error when try append element to document?

Why do I get error when try to convert Carbon to DateTime?

Why do I get Unable to create container with image Unable to pull image error pulling image when using multiple Docker hosts?

I get the error "error: CL/cl.h: No such file or directory" when I try to build a project on Qt

Why I obtain this error when I try to build a Java.utile.Date object from a String?

Why do I get an error when I blit an image

I get an error when I try to run yarn build in next.js

I get the following error when i try to connect sonarqube with azure devops build pipeline

When I try to build app by Android studio , I get the following error that the Gradle tasks connects timeout

I get this error when I try to install

Why am I getting this error when I try to type Text() or Image() in Button(action: {})?

Why Do I get an error when I try to get tkinter slider value?

Why does this non-descriptive error happen when I try to build this mxml file?

Why does AngularJS throw an error when I try to build a URL for an iframe src attribute?

Why does a C3889 Error occur in xutility when I try to build/generate a C++ solution?

I get Metadata.framework error when I try to import an image

Using React Native, I get an error when I try to use a background image

I get an error when I try to change my upload image function name Django

Why does audio.buffered.end(0) get an error message when I try to get buffered time

React App: Why I get an error when I try to run npm start script?

Why do I get a NoClassDefFound error when I try to save my test plan?