Reputation:
I want to use a .env-file
to describe my variables:
URL: $HOST
PORT: $PORT
MAIL = “[email protected]”
PASS = “test123"
I want to use the file in my container:
docker run --env-file myfile
But I want to replace the $HOST and $PORT in my file Can I do something like this?
docker run --env-file myfile -e PORT="8080" -e "HOST=ec2-xxx"
Upvotes: 0
Views: 937
Reputation: 1901
This is already supported, only thing is you need to make sure your ENV file is properly formatted:
$ cat myfile
URL= $HOST
PORT= $PORT
MAIL= “[email protected]”
PASS= “test123
Once your env-file is properly formatted, you could use the docker run command as follows:
$ docker run --env-file=myfile -e HOST=123.22 -e PORT=234 busybox env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=0d543af16a70
URL= $HOST
PORT=234
MAIL= “[email protected]”
PASS= “test123
HOST=123.22
HOME=/root
Please observe, in the above docker run command "busybox" is a container and
env
is the command that gets executed on running the above command. In your case, you may change the container name, and be assured that the env variables are properly sent.
Upvotes: 2