docker-machine可以创建一个虚拟的docker
当我运行
[root@VM_0_4_centos bin]# docker-machine create -d virtualbox manager
-bash: /usr/local/bin/docker-machine: Permission denied
表示我没有权限访问,当我添加sudo -i 后,提示找不到docker-machine命令
command not found
1.此时我们需要安装docker-machine
curl -L https://github.com/docker/machine/releases/download/v0.16.2/docker-machine-`uname -s`-`uname -m` >/usr/local/bin/docker-machine && \
chmod +x /usr/local/bin/docker-machine
2.安装之后再通过前面的创建命令,发现还是有问题
[root@VM_0_4_centos bin]# docker-machine create -d virtualbox manager
Creating CA: /root/.docker/machine/certs/ca.pem
Creating client certificate: /root/.docker/machine/certs/cert.pem
Running pre-create checks...
Error with pre-create check: "VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path"
这个报错,好像是因为centos7环境不支持virtualbox驱动(这个点我也有点迷,以后再深究)。
3.将驱动换成generic驱动。官网介绍:https://docs.docker.com/machine/drivers/generic/
[root@VM_0_4_centos bin]# docker-machine create -d generic --generic-ip-address=193.112.17.50 --generic-ssh-key ~/.ssh/id_rsa --generic-ssh-user=root vm
Running pre-create checks...
Error with pre-create check: "SSH key does not exist: \"/root/.ssh/id_rsa\""
蛋疼,又报错了。原来这是要进行ssh认证。行吧,那就认证吧
4.ssh认证,注意下面括号中的描述,小白的坑踩的死死的。
[root@VM_0_4_centos bin]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa (这里填写的是保存密钥的路径,千万别自定义,不然后面会报一堆莫名奇妙的错误,我被坑的死去活来,还是乖乖的用默认的吧)
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:nfJQqWsBWumFF/glAI1EmRxTAnSYEf2MHl76vjm6XJ8 root@VM_0_4_centos
The key's randomart image is:
+---[RSA 2048]----+
| .=@OOoo. |
| o.*ooo.... |
| +=.ooo |
| o+++.+ . |
| o.+. S o |
| + * |
| .. o . |
| . .o+ . |
| +++oE |
+----[SHA256]-----+
[root@VM_0_4_centos bin]# ssh-copy-id root@193.112.17.50
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@193.112.17.50's password: (这里填写用户登录密码)
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@193.112.17.50'"
and check to make sure that only the key(s) you wanted were added.
5.总算可以创建了吧,创建试试“ docker-machine create -d generic --generic-ip-address=193.112.17.50 --generic-ssh-key id_rsa --generic-ssh-user=root manager”
[root@VM_0_4_centos bin]# docker-machine create -d generic --generic-ip-address=193.112.17.50 --generic-ssh-key id_rsa --generic-ssh-user=root manager
Running pre-create checks...
Creating machine...
(manager) Importing SSH key...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Error creating machine: Error detecting OS: Too many retries waiting for SSH to be available. Last error: Maximum number of retries (60) exceeded
[root@VM_0_4_centos bin]# docker-machine create -d generic --generic-ip-address=193.112.17.50 --generic-ssh-key ~/.ssh/id_rsa --generic-ssh-user=root vm
Running pre-create checks...
Creating machine...
(vm) Importing SSH key...
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 centos...
Error creating machine: Error running provisioning: something went wrong running an SSH command
command : sudo systemctl -f restart docker
err : exit status 1
output : Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
等了N久,还是报错了,简直要疯了。。。稳住稳住,度娘告诉我说要删除重装docker。行吧,反正没啥东西,来,试试。
6.删除重装docker
命令行:
删除:
yum remove docker-*
更新:
yum update
---切记更新完之后重启系统
安装:
yum install docker
启动:
systemctl start docker
详细界面展示:
[root@vm ~]# yum remove docker-*
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 2:1.13.1-103.git7f2769b.el7.centos will be erased
---> Package docker-client.x86_64 2:1.13.1-103.git7f2769b.el7.centos will be erased
---> Package docker-common.x86_64 2:1.13.1-103.git7f2769b.el7.centos will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================================================================================================================
Removing:
docker x86_64 2:1.13.1-103.git7f2769b.el7.centos @extras 65 M
docker-client x86_64 2:1.13.1-103.git7f2769b.el7.centos @extras 13 M
docker-common x86_64 2:1.13.1-103.git7f2769b.el7.centos @extras 4.4 k
Transaction Summary
=================================================================================================================================================================================================================================================
Remove 3 Packages
Installed size: 77 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : 2:docker-1.13.1-103.git7f2769b.el7.centos.x86_64 1/3
warning: /etc/sysconfig/docker-storage saved as /etc/sysconfig/docker-storage.rpmsave
warning: /etc/docker/daemon.json saved as /etc/docker/daemon.json.rpmsave
Erasing : 2:docker-client-1.13.1-103.git7f2769b.el7.centos.x86_64 2/3
Erasing : 2:docker-common-1.13.1-103.git7f2769b.el7.centos.x86_64 3/3
Verifying : 2:docker-common-1.13.1-103.git7f2769b.el7.centos.x86_64 1/3
Verifying : 2:docker-1.13.1-103.git7f2769b.el7.centos.x86_64 2/3
Verifying : 2:docker-client-1.13.1-103.git7f2769b.el7.centos.x86_64 3/3
Removed:
docker.x86_64 2:1.13.1-103.git7f2769b.el7.centos docker-client.x86_64 2:1.13.1-103.git7f2769b.el7.centos docker-common.x86_64 2:1.13.1-103.git7f2769b.el7.centos
Complete!
[root@vm ~]# yum update
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
No packages marked for update
[root@vm ~]# Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(新建会话) at 21:02:20.
Type `help' to learn how to use Xshell prompt.
[C:\~]$
(这里在重启实例,因为前面我都是没有重启的,一直不行。。。。然后update后重启,果然可以了)
Connecting to 193.112.17.50:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Last login: Mon Dec 30 21:00:40 2019 from 116.24.66.181
[root@vm ~]# yum install docker
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 2:1.13.1-103.git7f2769b.el7.centos will be installed
--> Processing Dependency: docker-common = 2:1.13.1-103.git7f2769b.el7.centos for package: 2:docker-1.13.1-103.git7f2769b.el7.centos.x86_64
--> Processing Dependency: docker-client = 2:1.13.1-103.git7f2769b.el7.centos for package: 2:docker-1.13.1-103.git7f2769b.el7.centos.x86_64
--> Running transaction check
---> Package docker-client.x86_64 2:1.13.1-103.git7f2769b.el7.centos will be installed
---> Package docker-common.x86_64 2:1.13.1-103.git7f2769b.el7.centos will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================================================================================================================
Installing:
docker x86_64 2:1.13.1-103.git7f2769b.el7.centos extras 18 M
Installing for dependencies:
docker-client x86_64 2:1.13.1-103.git7f2769b.el7.centos extras 3.9 M
docker-common x86_64 2:1.13.1-103.git7f2769b.el7.centos extras 97 k
Transaction Summary
=================================================================================================================================================================================================================================================
Install 1 Package (+2 Dependent packages)
Total download size: 22 M
Installed size: 77 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): docker-client-1.13.1-103.git7f2769b.el7.centos.x86_64.rpm | 3.9 MB 00:00:00
(2/3): docker-common-1.13.1-103.git7f2769b.el7.centos.x86_64.rpm | 97 kB 00:00:00
(3/3): docker-1.13.1-103.git7f2769b.el7.centos.x86_64.rpm | 18 MB 00:00:16
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 1.3 MB/s | 22 MB 00:00:17
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 2:docker-common-1.13.1-103.git7f2769b.el7.centos.x86_64 1/3
Installing : 2:docker-client-1.13.1-103.git7f2769b.el7.centos.x86_64 2/3
Installing : 2:docker-1.13.1-103.git7f2769b.el7.centos.x86_64 3/3
Verifying : 2:docker-common-1.13.1-103.git7f2769b.el7.centos.x86_64 1/3
Verifying : 2:docker-1.13.1-103.git7f2769b.el7.centos.x86_64 2/3
Verifying : 2:docker-client-1.13.1-103.git7f2769b.el7.centos.x86_64 3/3
Installed:
docker.x86_64 2:1.13.1-103.git7f2769b.el7.centos
Dependency Installed:
docker-client.x86_64 2:1.13.1-103.git7f2769b.el7.centos docker-common.x86_64 2:1.13.1-103.git7f2769b.el7.centos
Complete!
[root@vm ~]# systemctl start docker
7.再来创建,终于可以了
[root@manager ~]# docker-machine create -d generic --generic-ip-address=193.112.17.50 --generic-ssh-key ~/.ssh/id_rsa --generic-ssh-user=root manager
Running pre-create checks...
Creating machine...
(manager) Importing SSH key...
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 centos...
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!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env manager
[root@manager ~]# docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
manager - generic Running tcp://193.112.17.50:2376 v1.13.1
到此位置,虚拟docker可以创建了,但是发现驱动不是我最开始的驱动。。。难道virtualbox驱动真的不行么,我不信,继续踩坑。。。。
.。。。。。。。
确实不可以,我用的本来就是云服务器。已经是一个虚拟化环境了。。。
在虚拟环境中跑虚拟机,无异于小鸡生小鸡,哈哈哈。。。
不过还是有的服务器可以做到,例如 Azure 的最新 EV3 型号,就支持嵌套虚拟化。在里面再开 hyperv 或者装 vmware 都可以