docker machine
Posted chenyishi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker machine相关的知识,希望对你有一定的参考价值。
环境
docker-machine主机:192.168.1.9
docker主机:192.168.1.10
步骤:
安装docker-machine
[[email protected] ~]# curl -L https://github.com/docker/machine/releases/download/v0.14.0/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 617 0 617 0 0 390 0 --:--:-- 0:00:01 --:--:-- 390 100 26.7M 100 26.7M 0 0 1618k 0 0:00:16 0:00:16 --:--:-- 3622k [[email protected] ~]# chmod +x /tmp/docker-machine [[email protected] ~]# cp /tmp/docker-machine /usr/local/bin/docker-machine [[email protected] ~]# ll /usr/local/bin/docker-machine -rwxr-xr-x 1 root root 28034848 6月 12 15:24 /usr/local/bin/docker-machine [[email protected] ~]# docker-machine -v docker-machine version 0.14.0, build 89b8332
创建ssh密钥对,实现两主机无密登录
[[email protected] ~]# ssh-keygen [[email protected] ~]# ssh-copy-id 192.168.1.10
创建docker主机,命名host1
[[email protected] ~]# docker-machine create -d generic --generic-ip-address=192.168.1.10 host1 Running pre-create checks... Creating machine... (swarm-master) No SSH key specified. Assuming an existing key at the default location. 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... Running... [[email protected] ~]# docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS host1 - generic Running tcp://192.168.1.10:2376 v17.12.1-ce
变更docker环境变量
[[email protected] ~]# docker-machine env host1 export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.1.10:2376" export DOCKER_CERT_PATH="/root/.docker/machine/machines/host1" export DOCKER_MACHINE_NAME="host1" # Run this command to configure your shell: # eval $(docker-machine env host1) [[email protected] ~]# eval $(docker-machine env host1)
运行容器查看两端是否同步
[[email protected] ~]# docker run -d busybox [[email protected] ~]# docker-machine ssh host1 [[email protected] ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE busybox latest f6e427c148a7 6 days ago 1.15MB [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8d9b5005a264 busybox "sh" 17 seconds ago Up 16 seconds ago modest_joliot [[email protected] ~]# exit [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8d9b5005a264 busybox "sh" 57seconds ago Up 16 seconds ago modest_joliot
镜像容器同步测试成功
以上是关于docker machine的主要内容,如果未能解决你的问题,请参考以下文章