3

How to set node ENV process.env.mysql-host with docker run?

Can i somehow do like this? docker run --mysql-host:127.0.0.1 -p 80:80 -d myApp

I am using FROM node:onbuild as image.

3 Answers 3

5

Node's process.env is an object containing the user environment. Docker's CLI allows you to set the environment variable for the container using the -e or --env options.

You can run

docker run --env mysql_host=127.0.0.1 -p 80:80 -d myApp

To pass the mysql_host into the container.

Sign up to request clarification or add additional context in comments.

Comments

5

I don't know much about node, but I think you just need to do:

docker run -e mysql-host=127.0.0.1 -p 80:80 -d myApp

Note that this will look for mysql-host in the same container, not on the host, if that's what you're expecting. I think what you really want to do is:

$ docker run -d --name db mysql
...
$ docker run -d --link db:mysql-host -p 80:80 -d myApp

Which will run the myApp container linked to the db container and resolvable as "mysql-host" inside the myApp container with no need for environment variables.

Comments

2

you could also set node ENV process.env.mysql-host inside your dockerfile

FROM node:latest

WORKDIR /home/app

ADD . /home/app

ENV PORT 3000 
ENV mysql-host 127.0.0.1

EXPOSE 3000

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.