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

  • How to configure nginx to forward all unhandled domains to particular service?
  • Secrets with containerized single-node kubernetes cluster
  • docker run cannot find name flag argument
  • Docker network does not work with bash entrypoint
  • How can I specify the machine in docker swarm mode?
  • Dockerfile error, “<filename> not found” on run docker
    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?

  • Mongo DB collections are not found
  • Push to port-forwarded docker registry
  • Kubernetes ACS engine: containers (pods) do not have internet access
  • Confuse about docker's -i “Keep STDIN open even if not attached”
  • Store and Restore Inherited Dockerfile USER setting
  • Visual Studio Team Service fails Task Docker Build
  • 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.