set docker-machine variables using a bash script

I have a script like so:

#!/usr/bin/env bash
eval $(docker-machine env default)

The goal is to automate the setting of variables like

  • Docker-compose on Windows 7: how to import a db dump when using a yaml file?
  • Easiest way to deploy with docker-compose?
  • postfix docker doesn't relay emails
  • Docker connection issue - connection timeout
  • Kitchen-Docker and Systemd
  • How to run shell script on host from docker container?
    export DOCKER_HOST

    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?

  • gcloud docker push no space left error
  • Docker Swarm Linking
  • Docker: reload a nodejs app with nodemon
  • How do I run nginx -t when nginx is running inside a docker container? [duplicate]
  • Travis ci in docker failing
  • wso2CEP on docker - supports JMS (activemq) and other clients
  • 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.

    $ ./
    DOCKER_HOST is tcp://
    $ echo "[$DOCKER_HOST]"

    When you source a script, the variables will be set in your current environment

    $ .
    DOCKER_HOST is tcp://
    $ echo "[$DOCKER_HOST]"
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.