安裝
[官方Release庫(kù):]https://github.com/docker/machine/releases/
[官方安裝文檔:]https://docs.docker.com/machine/install-machine/
base=https://github.com/docker/machine/releases/download/v0.16.0 &&
curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine &&
sudo mv /tmp/docker-machine /usr/local/bin/docker-machine &&
chmod +x /usr/local/bin/docker-machine
安裝完成后,查看docker-machine版本
[root@localhost tmp]# docker-machine -v
docker-machine version 0.16.0, build 702c267f
為了支持命令自動(dòng)補(bǔ)全,還可以安裝補(bǔ)全腳本:
scripts=(docker-machine-prompt.bash docker-machine-wrapper.bash docker-machine.bash); for i in "${scripts[@]}"; do wget https://raw.githubusercontent.com/docker/machine/v0.16.0/contrib/completion/bash/${i} -P /etc/bash_completion.d; done
采用generic驅(qū)動(dòng)給另一個(gè)主機(jī)安裝docker
官方文檔:
[generic驅(qū)動(dòng)]https://docs.docker.com/machine/drivers/generic/
- 需要有ssh公鑰彭雾,沒(méi)有就生成一個(gè): ssh-keygen
- 復(fù)制到遠(yuǎn)程主機(jī): ssh-copy-id your ip
- docker-machine create -d generic --generic-ip-address=ip地址 --generic-ssh-key ~/.ssh/id_rsa --generic-ssh-user=root 194210
這一步遇到了問(wèn)題,輸出顯示沒(méi)有啟動(dòng)成功
Running pre-create checks...
Creating machine...
(194210) 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.
連到遠(yuǎn)程主機(jī)上跋核,上面的報(bào)錯(cuò)不夠詳細(xì),看看systemctl里docker服務(wù)的內(nèi)容
cat /etc/systemd/system/docker.service.d/10-machine.conf
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --storage-driver overlay2 --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem --label provider=generic
把ExecStart的內(nèi)容拿出來(lái)執(zhí)行一下
/usr/bin/dockerd -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --storage-driver overlay2
INFO[2019-09-04T13:59:16.648204922+08:00] Starting up
WARN[2019-09-04T13:59:16.648556107+08:00] [!] DON'T BIND ON ANY IP ADDRESS WITHOUT setting --tlsverify IF YOU DON'T KNOW WHAT YOU'RE DOING [!]
INFO[2019-09-04T13:59:16.649641583+08:00] parsed scheme: "unix" module=grpc
INFO[2019-09-04T13:59:16.649667372+08:00] scheme "unix" not registered, fallback to default scheme module=grpc
INFO[2019-09-04T13:59:16.649710791+08:00] ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock 0 <nil>}] } module=grpc
INFO[2019-09-04T13:59:16.649732778+08:00] ClientConn switching balancer to "pick_first" module=grpc
INFO[2019-09-04T13:59:16.649842261+08:00] pickfirstBalancer: HandleSubConnStateChange: 0xc0007486d0, CONNECTING module=grpc
INFO[2019-09-04T13:59:16.650179805+08:00] pickfirstBalancer: HandleSubConnStateChange: 0xc0007486d0, READY module=grpc
INFO[2019-09-04T13:59:16.651005252+08:00] parsed scheme: "unix" module=grpc
INFO[2019-09-04T13:59:16.651025012+08:00] scheme "unix" not registered, fallback to default scheme module=grpc
INFO[2019-09-04T13:59:16.651038259+08:00] ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock 0 <nil>}] } module=grpc
INFO[2019-09-04T13:59:16.651045861+08:00] ClientConn switching balancer to "pick_first" module=grpc
INFO[2019-09-04T13:59:16.651096185+08:00] pickfirstBalancer: HandleSubConnStateChange: 0xc00070dc70, CONNECTING module=grpc
INFO[2019-09-04T13:59:16.651364815+08:00] pickfirstBalancer: HandleSubConnStateChange: 0xc00070dc70, READY module=grpc
failed to start daemon: error initializing graphdriver: overlay2: the backing xfs filesystem is formatted without d_type support, which leads to incorrect behavior. Reformat the filesystem with ftype=1 to enable d_type support. Backing filesystems without d_type support are not supported.
看這一句:error initializing graphdriver: overlay2: the backing xfs filesystem is formatted without d_type support叛买,搜索了一下
[參考一]https://blog.csdn.net/weixin_41826563/article/details/80549323
[參考二]https://blog.csdn.net/liukuan73/article/details/77986139
這里要說(shuō)明一下砂代,本文中的遠(yuǎn)程主機(jī)系統(tǒng)是centos7.2,和分區(qū)有關(guān)系,這里選另一種方法聪全,把ExecStart里的--storage-driver overlay2去掉
然后在遠(yuǎn)程主機(jī)上執(zhí)行:
systemctl daemon-reload
systemctl start docker
可以看到docker啟動(dòng)了,docker info看到Storage Driver類型是:devicemapper
- 看一下194210這個(gè)環(huán)境
docker-machine env 194210
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://10.129.194.210:2376"
export DOCKER_CERT_PATH="/root/.docker/machine/machines/194210"
export DOCKER_MACHINE_NAME="194210"
# Run this command to configure your shell:
# eval $(docker-machine env 194210)
現(xiàn)在可從docker-machine管理194210的docker了
先加載環(huán)境變量
eval $(docker-machine env 194210)
運(yùn)行一個(gè)容器試試
docker run -it python:3.6.5-alpine sh
/ # python
Python 3.6.5 (default, Jun 6 2018, 23:08:29)
[GCC 6.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello World!")
Hello World!
可以ssh到遠(yuǎn)程主機(jī)上看效果
退出194210的docker環(huán)境泊藕,實(shí)際上就是去掉DOCKER的幾個(gè)環(huán)境變量
dockerenv=(DOCKER_TLS_VERIFY DOCKER_HOST DOCKER_CERT_PATH DOCKER_MACHINE_NAME);for i in ${dockerenv[@]}; do unset $i; done