Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot pass env variables to docker

I am trying to run a docker image with env variables.

But it doesn't work for me either with env.list file or by command line.

docker run -p 49160:8080 -d appname -e FOO='foo'

Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"-e\": executable file not found in $PATH": unknown.

run -p 49160:8080 -d appname --env-file ./env.list

Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"--env-file\": executable file not found in $PATH": unknown.

It does run if I just go:

docker run -p 49160:8080 -d appname

Dockerfile:

FROM node:latest
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app
EXPOSE 8080
CMD [ "npm", "start" ]
like image 437
Alon Avatar asked Jan 07 '19 15:01

Alon


People also ask

How do I pass environment variables to docker containers?

Using –env, -e When we launch our Docker container, we can pass environment variables as key-value pairs directly into the command line using the parameter –env (or its short form -e). As can be seen, the Docker container correctly interprets the variable VARIABLE1.

Can Dockerfile access environment variables?

Dockerfile provides a dedicated variable type ENV to create an environment variable. We can access ENV values during the build, as well as once the container runs.

Does docker use .env file?

Here's a list of easy takeaways: The . env file, is only used during a pre-processing step when working with docker-compose. yml files.

How do you pass an environment variable?

Environment variables can be used to pass configuration to an application when it is run. This is done by adding the definition of the environment variable to the deployment configuration for the application. To add a new environment variable use the oc set env command.


1 Answers

You need to place your environment variables before the image's name. Try this:

docker run -e FOO='foo' -p 49160:8080 -d appname
like image 52
molamk Avatar answered Oct 19 '22 12:10

molamk