How to set environment variables via env-file

I have a Dockerfile based on the spring guide about docker. My application consumes some private data, so I want to pass these parameters through environment variables. When I run a docker container:

docker run -p 8080:8080 -t myname/myapplication --env-file=~/env.list

it appears that the variables are not set and the application can’t see them, what do I do wrong? How to pass these parameters?

  • Docker run with pseudoTTY (-t) gives instant stdout, buffering happens without it
  • Connection reset by peer error TensorFlow
  • Cannot connect to docker mongo
  • Dockerized gitlab use host docker to CI
  • Should I created three images for Apache http server, php and memcached separately?
  • Setting .htcaccess in an external volume for Docker not working
  • env.list:

    ACCOUNT_ID=my_account_id
    ACCOUNT_PASSWORD=my_secret_password
    

    My ENTRYPOINT:

    ENTRYPOINT java -Djava.security.egd=file:/dev/./urandom -jar $APPLICATION_NAME
    

  • Errors with alpine linux 3.5 and ruby 2.0?
  • How to configure PHP 7 - Apache with MySQL PDO driver in Debian Docker image?
  • Logstash with fluent input codec not working
  • How do you put your source code into Kubernetes?
  • Jenkins pipeline docker.image call generates a timeout
  • Github repo with more than one python packages
  • 2 Solutions collect form web for “How to set environment variables via env-file”

    I think

    docker run

    takes all parameters before the image and the command. If I do

    docker run -t --env-file=env.list ubuntu sh -c "while true; do echo world; sleep 100 ;done"

    and then

    docker exec -it container_id env

    I get

    HOSTNAME=195f18677a91
    TERM=xterm
    ACCOUNT_ID=my_account_id
    ACCOUNT_PASSWORD=my_secret_password
    HOME=/root

    Try

    docker run -p 8080:8080 --env-file=~/env.list -t myname/myapplication

    This works very well:

    cat <<EOF > test.env
    MYVAR=test
    EOF
    docker run -it --env-file test.env busybox env | grep MYVAR
    

    That will print as expected:

    MYVAR=test
    

    In your case in your Java application you can access the environment variables via System.getenv().

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.