Published 6月 13, 2019 by with 0 comment

6 - 03 - Manage Machine



In this lab, I will use Docker Machine to manage machine. For example, setting some docker commands without login to machine.


1. Use docker-machine ls to list available machines.
[peter@peter-KVM ~]$ docker-machine ls
NAME    ACTIVE   DRIVER    STATE     URL                          SWARM   DOCKER     ERRORS
host1   -        generic   Running   tcp://192.168.122.251:2376           v18.09.6   
host2   -        generic   Running   tcp://192.168.122.64:2376            v18.09.6   
[peter@peter-KVM ~]$ 


2. Get the environment commands for your new VM
[peter@peter-KVM ~]$ docker-machine env host1
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.122.251:2376"
export DOCKER_CERT_PATH="/home/peter/.docker/machine/machines/host1"
export DOCKER_MACHINE_NAME="host1"
# Run this command to configure your shell: 
# eval $(docker-machine env host1)
[peter@peter-KVM ~]$ 
[peter@peter-KVM ~]$ docker-machine env host2
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.122.64:2376"
export DOCKER_CERT_PATH="/home/peter/.docker/machine/machines/host2"
export DOCKER_MACHINE_NAME="host2"
# Run this command to configure your shell: 
# eval $(docker-machine env host2)
[peter@peter-KVM ~]$ 


3. Change the local docker environment variables to the host1
[peter@peter-KVM ~]$ eval $(docker-machine env host1)
[peter@peter-KVM ~ [host1]]$ 
[peter@peter-KVM ~ [host1]]$ docker-machine active
host1
[peter@peter-KVM ~ [host1]]$ 


4. Start two container (helle-world and busybox) in the host1
[peter@peter-KVM ~ [host1]]$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:41a65640635299bab090f783209c1e3a3f11934cf7756b09cb2f1e02147c6ed8
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

[peter@peter-KVM ~ [host1]]$ 
[peter@peter-KVM ~ [host1]]$ docker run -itd busybox
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
ff5eadacfa0b: Pull complete 
Digest: sha256:c888d69b73b5b444c2b0bd70da28c3da102b0aeb327f3a297626e2558def327f
Status: Downloaded newer image for busybox:latest
a28332936c8af30f3c114cdf60151b6a9c76be8cf8941919914876be0d562624
[peter@peter-KVM ~ [host1]]$ 
[peter@peter-KVM ~ [host1]]$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
a28332936c8a        busybox             "sh"                13 seconds ago      Up 11 seconds                           optimistic_roentgen
[peter@peter-KVM ~ [host1]]$ 


5. Change the host1 environment to the host2
[peter@peter-KVM ~ [host1]]$ eval $(docker-machine env host2)
[peter@peter-KVM ~ [host2]]$ 
[peter@peter-KVM ~ [host2]]$ docker-machine active 
host2
[peter@peter-KVM ~ [host2]]$ 


6. Go back to local instance.
[peter@peter-KVM ~ [host2]]$ eval $(docker-machine env -u)
[peter@peter-KVM ~]$ 
[peter@peter-KVM ~]$ docker-machine active 
No active host found
[peter@peter-KVM ~]$


最初發表 / 最後更新: 2019.06.13 / 2019.06.13

0 comments:

張貼留言