set docker-machine variables using a bash script
I have a script like so:
The goal is to automate the setting of variables like
export DOCKER_TLS_VERIFY export DOCKER_HOST export DOCKER_CERT_PATH export DOCKER_MACHINE_NAME
But when I check afterwards, the variables are not set. This is not the case if I run each
export command manually. What am I doing wrong?
2 Solutions collect form web for “set docker-machine variables using a bash script”
export makes variables available only to the active shell session. If you want them to persist through sessions, you must add them to your bash profile:
docker-machine env default >> ~/.bash_profile
This way, the variables will be available in all future shell sessions. Make sure to restart the shell after executing the command.
If you want the environment set in your current shell you need to “source” the script rather than run it.
When you run a script, the variables will be set in the child
bash processes environment and will not exist once that script/process dies.
$ ./machine.sh DOCKER_HOST is tcp://192.168.99.100:2376 $ echo "[$DOCKER_HOST]" 
When you source a script, the variables will be set in your current environment
$ . machine.sh DOCKER_HOST is tcp://192.168.99.100:2376 $ echo "[$DOCKER_HOST]" [tcp://192.168.99.100:2376]