Cannot pass env variables to docker

Viewed 6236

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" ]
3 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

as per documentation ... link

To set a value for a single command, use RUN key=value command.

try below.. for ex:

docker run --env LOG_DIR_PATH='/code/${LOG_DIR_PATH}'

Related