官网学习地址:https://docs.docker.com/v18.09/get-started/part4/
笔记总结:
那个用户执行这句话,需要保证对应的目录中有对应的iso文件:https://www.liujutan.com/test/soft/docker/boot2docker.iso---几乎所有的docker文件都在这里
创建集群
1、创建机器
# docker-machine create --driver virtualbox myvm1
Running pre-create checks...
(myvm1) No default Boot2Docker ISO found locally, downloading the latest release...
(myvm1) Latest release for github.com/boot2docker/boot2docker is v19.03.5
(myvm1) Downloading /root/.docker/machine/cache/boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v19.03.5/boot2docker.iso...
(myvm1) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
Creating machine...
(myvm1) Copying /root/.docker/machine/cache/boot2docker.iso to /root/.docker/machine/machines/myvm1/boot2docker.iso...
(myvm1) Creating VirtualBox VM...
(myvm1) Creating SSH key...
(myvm1) Starting the VM...
(myvm1) Check network to re-create if needed...
(myvm1) Found a new host-only adapter: "vboxnet0"
(myvm1) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
2、第一台计算机充当管理器,它执行管理命令并验证工作人员加入该群
# docker-machine ssh myvm1 "docker swarm init --advertise-addr 192.168.99.100" Swarm initialized: current node (o7gi1h1vknqvfxt4a9tkuhqe2) is now a manager. To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-08enh61yzcedrv3fcrw0z8xyx7nh4sn4zup5lnnwnb63vl23jg-72x6wtkq3qa411kcry1tmtocc 192.168.99.100:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
3、第二台计算机是工作人员,加入
$ docker-machine ssh myvm2 "docker swarm join \
--token <token> \
<ip>:2377"
This node joined a swarm as a worker.
实际就是 docker-machine ssh myvm2 "docker swarm join --token SWMTKN-1-08enh61yzcedrv3fcrw0z8xyx7nh4sn4zup5lnnwnb63vl23jg-72x6wtkq3qa411kcry1tmtocc 192.168.99.100:2377"
4、查看集群又什么机器:
$ docker-machine ssh myvm1 "docker node ls"
5、获取命令以配置要与之通信的Shell myvm1
$ docker-machine env myvm1
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/sam/.docker/machine/machines/myvm1"
export DOCKER_MACHINE_NAME="myvm1"
# Run this command to configure your shell:
# eval $(docker-machine env myvm1)
eval $(docker-machine env myvm1)
6、终端链接vm的三种办法
1、docker-machine env <machine> 2、docker-machine ssh <machine> "<command>" 3、docker-machine scp <file> <machine>:~
本章节,官网视频教学:https://asciinema.org/a/113837
您可能需要运行以下命令来与群集和VM进行一些交互:
docker-machine create --driver virtualbox myvm1 # Create a VM (Mac, Win7, Linux)
docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" myvm1 # Win10
docker-machine env myvm1 # View basic information about your node
docker-machine ssh myvm1 "docker node ls" # List the nodes in your swarm
docker-machine ssh myvm1 "docker node inspect <node ID>" # Inspect a node
docker-machine ssh myvm1 "docker swarm join-token -q worker" # View join token
docker-machine ssh myvm1 # Open an SSH session with the VM; type "exit" to end
docker node ls # View nodes in swarm (while logged on to manager)
docker-machine ssh myvm2 "docker swarm leave" # Make the worker leave the swarm
docker-machine ssh myvm1 "docker swarm leave -f" # Make master leave, kill swarm
docker-machine ls # list VMs, asterisk shows which VM this shell is talking to
docker-machine start myvm1 # Start a VM that is currently not running
docker-machine env myvm1 # show environment variables and command for myvm1
eval $(docker-machine env myvm1) # Mac command to connect shell to myvm1
& "C:\Program Files\Docker\Docker\Resources\bin\docker-machine.exe" env myvm1 | Invoke-Expression # Windows command to connect shell to myvm1
docker stack deploy -c <file> <app> # Deploy an app; command shell must be set to talk to manager (myvm1), uses local Compose file
docker-machine scp docker-compose.yml myvm1:~ # Copy file to node's home dir (only required if you use ssh to connect to manager and deploy the app)
docker-machine ssh myvm1 "docker stack deploy -c <file> <app>" # Deploy an app using ssh (you must have first copied the Compose file to myvm1)
eval $(docker-machine env -u) # Disconnect shell from VMs, use native docker
docker-machine stop $(docker-machine ls -q) # Stop all running VMs
docker-machine rm $(docker-machine ls -q) # Delete all VMs and their di
Comments | NOTHING