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" ]
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.
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.
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.
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.
You need to place your environment variables before the image's name. Try this:
docker run -e FOO='foo' -p 49160:8080 -d appname
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With