Unset machine environment

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)

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


Actually, I see machine has this command

docker-machine env --unset XXX

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.

unset ${!DOCKER_*}

1 Like

Based on the documentation: Overview of Docker Desktop | Docker Docs
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)

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

$ eval $(docker-machine env -u)
1 Like