How is a Docker Machine marked as active?

后端 未结 3 724
一生所求
一生所求 2021-02-01 05:20

I am working through the Docker Machine User Guide over at https://docs.docker.com/v1.5/machine/.

It says:

You can see the machine you have created by r         


        
3条回答
  •  無奈伤痛
    2021-02-01 05:47

    Its' pretty simple and the answer lies in the statement "a machine is considered active if the DOCKER_HOST environment variable points to it" from docker website: https://docs.docker.com/machine/reference/active/

    So, let's say initially:

    $ docker-machine ls
    
    NAME      ACTIVE   DRIVER         STATE     URL
    dev       -        virtualbox     Running   tcp://192.168.99.103:2376
    staging   *        digitalocean   Running   tcp://203.0.113.81:2376
    

    If you check:

    $ echo $DOCKER_HOST
    tcp://203.0.113.81:2376  ====> it will point to staging
    

    All you have to do now is (tried on Docker terminal):

    $ DOCKER_HOST=tcp://192.168.99.103:2376
    

    And now if you check:

    $ docker-machine ls
    
    NAME      ACTIVE   DRIVER         STATE     URL
    dev       *        virtualbox     Running   tcp://192.168.99.103:2376
    staging   -        digitalocean   Running   tcp://203.0.113.81:2376
    

    The active container has moved to 'dev'!! From now on all your commands like 'docker container ls' etc. should reflect your newly active container.

    But please note this arrangement will work only for the Docker terminal where you changed the default container i.e. if you close and re-open a new terminal or open another Docker terminal the original default container (staging in this example) will be active.

提交回复
热议问题