How to manage docker containers based on docker-machine

  今天我们来简要介绍一下docker-machine的用法。

1 安装

  在安装好docker-machine之前,务必要安装好docker\ Virtualbox,关于Docker的安装请参阅文章《Docker实战:Docker安装》一文。

lwk@qwfys:~$ sudo wget https://github.com/docker/machine/releases/download/v0.16.0/docker-machine-`uname -s`-`uname -m` -O /usr/local/bin/docker-machine
[sudo] password for lwk:       
--2019-06-29 12:38:21--  https://github.com/docker/machine/releases/download/v0.16.0/docker-machine-Linux-x86_64
Resolving github.com (github.com)... 52.74.223.119
Connecting to github.com (github.com)|52.74.223.119|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-production-release-asset-2e65be.s3.amazonaws.com/27494663/e85b8180-e350-11e8-8079-c3bbd3ef5d6a?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20190629%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190629T043823Z&X-Amz-Expires=300&X-Amz-Signature=b9452e0de5a6dfb5b6bfbd6b590ef3b4c5a7b371fc5b56254a348f9c67f4c6bb&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Ddocker-machine-Linux-x86_64&response-content-type=application%2Foctet-stream [following]
--2019-06-29 12:38:22--  https://github-production-release-asset-2e65be.s3.amazonaws.com/27494663/e85b8180-e350-11e8-8079-c3bbd3ef5d6a?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20190629%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190629T043823Z&X-Amz-Expires=300&X-Amz-Signature=b9452e0de5a6dfb5b6bfbd6b590ef3b4c5a7b371fc5b56254a348f9c67f4c6bb&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Ddocker-machine-Linux-x86_64&response-content-type=application%2Foctet-stream
Resolving github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)... 52.216.164.51
Connecting to github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)|52.216.164.51|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 28164576 (27M) [application/octet-stream]
Saving to: ‘/usr/local/bin/docker-machine’
/usr/local/bin/docker-machine                                1%[>                                                                                                                                         ] 322.56K  3.38KB/s    eta 2h 17m

lwk@qwfys:~$

OR

sudo curl -L -o /usr/local/bin/docker-machine https://github.com/docker/machine/releases/download/v0.16.2/docker-machine-`uname -s`-`uname -m` && sudo chmod +x /usr/local/bin/docker-machine

OR

sudo wget -c -O /usr/local/bin/docker-machine https://github.com/docker/machine/releases/download/v0.16.2/docker-machine-`uname -s`-`uname -m` && sudo chmod +x /usr/local/bin/docker-machine
lwk@qwfys:~$
lwk@qwfys:~$ sudo chmod +x /usr/local/bin/docker-machine
lwk@qwfys:~$ 
lwk@qwfys:~$ base=https://raw.githubusercontent.com/docker/machine/v0.16.0
lwk@qwfys:~$ for i in docker-machine-prompt.bash docker-machine-wrapper.bash docker-machine.bash
> do
>   sudo wget "$base/contrib/completion/bash/${i}" -P /etc/bash_completion.d
> done
[sudo] password for lwk:       
--2019-06-29 12:54:57--  https://raw.githubusercontent.com/docker/machine/v0.16.0/contrib/completion/bash/docker-machine-prompt.bash
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.76.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.76.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1469 (1.4K) [text/plain]
Saving to: ‘/etc/bash_completion.d/docker-machine-prompt.bash’

docker-machine-prompt.bash                                100%[=========================================================================================================================================>]   1.43K  --.-KB/s    in 0s      

2019-06-29 12:54:59 (95.7 MB/s) - ‘/etc/bash_completion.d/docker-machine-prompt.bash’ saved [1469/1469]

--2019-06-29 12:54:59--  https://raw.githubusercontent.com/docker/machine/v0.16.0/contrib/completion/bash/docker-machine-wrapper.bash
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.76.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.76.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1525 (1.5K) [text/plain]
Saving to: ‘/etc/bash_completion.d/docker-machine-wrapper.bash’

docker-machine-wrapper.bash                               100%[=========================================================================================================================================>]   1.49K  --.-KB/s    in 0s      

2019-06-29 12:55:00 (101 MB/s) - ‘/etc/bash_completion.d/docker-machine-wrapper.bash’ saved [1525/1525]

--2019-06-29 12:55:00--  https://raw.githubusercontent.com/docker/machine/v0.16.0/contrib/completion/bash/docker-machine.bash
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.76.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.76.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12211 (12K) [text/plain]
Saving to: ‘/etc/bash_completion.d/docker-machine.bash’

docker-machine.bash                                       100%[=========================================================================================================================================>]  11.92K  19.4KB/s    in 0.6s    

2019-06-29 12:55:02 (19.4 KB/s) - ‘/etc/bash_completion.d/docker-machine.bash’ saved [12211/12211]

lwk@qwfys:~$ source /etc/bash_completion.d/docker-machine-prompt.bash
lwk@qwfys:~$ docker-machine
Usage: docker-machine [OPTIONS] COMMAND [arg...]

Create and manage machines running Docker.

Version: 0.16.0, build 702c267f

Author:
  Docker Machine Contributors - <https://github.com/docker/machine>

Options:
  --debug, -D						Enable debug mode
  --storage-path, -s "/home/lwk/.docker/machine"	Configures storage path [$MACHINE_STORAGE_PATH]
  --tls-ca-cert 					CA to verify remotes against [$MACHINE_TLS_CA_CERT]
  --tls-ca-key 						Private key to generate certificates [$MACHINE_TLS_CA_KEY]
  --tls-client-cert 					Client cert to use for TLS [$MACHINE_TLS_CLIENT_CERT]
  --tls-client-key 					Private key used in client TLS auth [$MACHINE_TLS_CLIENT_KEY]
  --github-api-token 					Token to use for requests to the Github API [$MACHINE_GITHUB_API_TOKEN]
  --native-ssh						Use the native (Go-based) SSH implementation. [$MACHINE_NATIVE_SSH]
  --bugsnag-api-token 					BugSnag API token for crash reporting [$MACHINE_BUGSNAG_API_TOKEN]
  --help, -h						show help
  --version, -v						print the version
  
Commands:
  active		Print which machine is active
  config		Print the connection config for machine
  create		Create a machine
  env			Display the commands to set up the environment for the Docker client
  inspect		Inspect information about a machine
  ip			Get the IP address of a machine
  kill			Kill a machine
  ls			List machines
  provision		Re-provision existing machines
  regenerate-certs	Regenerate TLS Certificates for a machine
  restart		Restart a machine
  rm			Remove a machine
  ssh			Log into or run a command on a machine with SSH.
  scp			Copy files between machines
  mount			Mount or unmount a directory from a machine with SSHFS.
  start			Start a machine
  status		Get the status of a machine
  stop			Stop a machine
  upgrade		Upgrade a machine to the latest version of Docker
  url			Get the URL of a machine
  version		Show the Docker Machine version or a machine docker version
  help			Shows a list of commands or help for one command
  
Run 'docker-machine COMMAND --help' for more information on a command.
lwk@qwfys:~$ docker-machine version
docker-machine version 0.16.0, build 702c267f
lwk@qwfys:~$ 

  至此docker machine安装完成。

2 创建虚拟机

lwk@qwfys:~$ ll ~/Downloads/boot2docker.iso 
-rw-rw-r-- 1 lwk lwk 47185920 Jun 28 10:20 /home/lwk/Downloads/boot2docker.iso
lwk@qwfys:~$
lwk@qwfys:~$ docker-machine create --driver virtualbox --virtualbox-boot2docker-url=file:///home/lwk/Downloads/boot2docker.iso default
Running pre-create checks...
Creating machine...
(default) Downloading /home/lwk/.docker/machine/cache/boot2docker.iso from file:///home/lwk/Downloads/boot2docker.iso...
(default) Creating VirtualBox VM...
(default) Creating SSH key...
(default) Starting the VM...
(default) Check network to re-create if needed...
(default) Found a new host-only adapter: "vboxnet0"
(default) 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!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env default
lwk@qwfys:~$ 
lwk@qwfys:~$ docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER     ERRORS
default   -        virtualbox   Running   tcp://192.168.99.100:2376           v18.09.7   
lwk@qwfys:~$
lwk@qwfys:~$ docker-machine env default 
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/home/lwk/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell: 
# eval $(docker-machine env default)
lwk@qwfys:~$ 
lwk@qwfys:~$ docker-machine ssh default
   ( '>')
  /) TC (\   Core is distributed with ABSOLUTELY NO WARRANTY.
 (/-_--_-\)           www.tinycorelinux.net

docker@default:~$ 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qwfys200

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值