Home > database >  Can a Docker container access env variables I've set on the server?
Can a Docker container access env variables I've set on the server?

Time:08-25

I have a twitter bot which I am attempting to deploy to my server with Docker; I don't want to save my API keys & Access Tokens in the code, so I access them via env variables.

I ssh'ed into the server and exported the keys & tokens in my ~/.profile, yet when I run the Docker container on my server, I get an error as if my keys/tokens are incorrect.

I'm new to Docker so I have to ask - Is my running Docker container able to access these env variables? Or do I have to set them another way such that my Docker container can see them?

CodePudding user response:

Docker can't access the env vars on the server. You need to pass them explicitly when running the docker using -e / --env flag.

Example: docker run --env VAR1=value1 --env VAR2=value2 ...

Documentation: https://docs.docker.com/engine/reference/commandline/run

  • Related