Docker Community Forums

Share and learn in the Docker community.

Unset machine environment

(Tony Pujals) #1

When setting the environment for using a Docker machine (eval “$(docker-machine env )”) and then switching back to using the environment for Docker for Mac, is there a standard way to unset the machine environment?

I set up the following function in my .bashrc file to clear all the DOCKER_x environment variables set for using a machine, but wondering if there’s a standard way that I’m just not aware of:

mc() {
  unset $(env | grep DOCKER | awk -F'=' '{print $1}' | xargs)

(John Pape) #2

AFAIK, this is the only way. I generally just do a


Actually, I see machine has this command

docker-machine env --unset XXX

(Tony Pujals) #3

Thanks. Yeah, unsetting DOCKER_MACHINE_NAME or setting it equal to an empty string accomplishes the same thing. I was being abundantly cautious in unsetting all the environment variables that were set via docker-machine env. I just thought that there might be a canonical way to do this.

(Everett Toews) #4

unset ${!DOCKER_*}

(Codefist) #5

Based on the documentation:
I use this bash function:

undock() {
  eval $(docker-machine env -u)

and as a sidenote I use this function for “docking”

dock() {
  eval $(docker-machine env $1)

(Nathan Le Claire) #6

Yep, docker-machine env -u was invented for this purpose.

$ eval $(docker-machine env -u)