Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Env variable in Dockerfile

I'm trying to dockerize a basic nodejs app. My dockerfile is the follow

FROM node:10

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 80
CMD [ "node", "index.js" ]

After i build the image I'm trying to running it with

docker run -p 3000:3000 imagename -e connectionString=myConnString

But I received always the same error

[eval]:1
connectionString=myConnString

ReferenceError: myConnString is not defined

How can I solve?

like image 538
Manuel Castro Avatar asked Jan 01 '26 03:01

Manuel Castro


1 Answers

The docker run syntax is docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...], anything passed after the IMAGE[:TAG|@DIGEST] is passed as [COMMAND] [ARG...].

The environment variable setting should be passed in the run [OPTIONS] i.e.: docker run -p 3000:3000 -e connectionString=myConnString imagename

like image 122
masseyb Avatar answered Jan 04 '26 01:01

masseyb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!