mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
[Translated] 20150520 How to Use Docker Machine with a Cloud Provider.md
This commit is contained in:
parent
78efea9001
commit
82ddcd4baa
@ -1,149 +0,0 @@
|
||||
Translating by goreliu ...
|
||||
|
||||
How to Use Docker Machine with a Cloud Provider
|
||||
================================================================================
|
||||
Hi everyone, today we'll learn how we can use Docker Machine to deploy Docker host in various Cloud Provider Platforms. Docker Machine is an application that helps to create Docker hosts on our computer, on cloud providers and inside our own data center. It provides easy solution for creating servers, installing Docker on them and then configuring the Docker client according the users configuration and requirements. The driver APIs works for provisioning Docker on a local machine, on a virtual machine in the data center, or on a public cloud instance. Docker Machine is supported on Windows, OSX, and Linux and is available for installation as one standalone binary. It enables us to take full advantage of ecosystem partners providing Docker-ready infrastructure, while still accessing everything through the same interface. It makes people able to deploy the docker containers in the respective cloud platform pretty fast and in pretty easy way with just a single command.
|
||||
|
||||
### 1. Installing Docker Machine ###
|
||||
|
||||
Docker Machine supports awesome on every Linux Operating System. First of all, we'll need to download the latest version of Docker Machine from the Github site . Here, we'll use curl to download the latest version of Docker Machine ie 0.2.0 .
|
||||
|
||||
For 64 Bit Operating System
|
||||
|
||||
# curl -L https://github.com/docker/machine/releases/download/v0.2.0/docker-machine_linux-amd64 > /usr/local/bin/docker-machine
|
||||
|
||||
For 32 Bit Operating System
|
||||
|
||||
# curl -L https://github.com/docker/machine/releases/download/v0.2.0/docker-machine_linux-i386 > /usr/local/bin/docker-machine
|
||||
|
||||
After downloading the latest release of Docker Machine, we'll make the file named docker-machine under /usr/local/bin/ executable using the command below.
|
||||
|
||||
# chmod +x /usr/local/bin/docker-machine
|
||||
|
||||
After doing the above, we'll wanna ensure that we have successfully installed docker-machine. To check it, we can run the docker-machine -v which will give output of the version of docker-machine installed in our system.
|
||||
|
||||
# docker-machine -v
|
||||
|
||||
![Installing Docker Machine](http://blog.linoxide.com/wp-content/uploads/2015/05/installing-docker-machine.png)
|
||||
|
||||
To enable Docker commands on our machines, make sure to install the Docker client as well by running the command below.
|
||||
|
||||
# curl -L https://get.docker.com/builds/linux/x86_64/docker-latest > /usr/local/bin/docker
|
||||
# chmod +x /usr/local/bin/docker
|
||||
|
||||
### 2. Creating Machine ###
|
||||
|
||||
After finish installing Docker Machine in our Linux box, we'll wanna deploy a docker host into the cloud server. Docker Machine includes drivers for several popular Cloud Platforms such as Digital Ocean, Amazon Web Services (AWS), Microsoft Azure, Google Cloud Computing and many other which enables us to create same interface of docker deployment in different platforms. So, here in this tutorial we'll gonna deploy the Docker Host into the Digital Ocean server using digitalocean driver API. Here, we'll need to run command docker-machine create followed by --driver flag as digitalocean with --digitalocean-access-token flag as the API Token provided by the [Digital Ocean Control Panel][1] and at last the name of the docker host we just created. To do so, we'll need to run the following command as.
|
||||
|
||||
# docker-machine create --driver digitalocean --digitalocean-access-token <API-Token> linux-dev
|
||||
|
||||
# eval "$(docker-machine env linux-dev)"
|
||||
|
||||
![Docker Machine Digitalocean Cloud](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-digitalocean-cloud.png)
|
||||
|
||||
**Note**: Here, linux-dev is the name of the machine we are wanting to create. <API-Token> is a security key which can be generated from the Digital Ocean Control Panel of the account holder of Digital Ocean Cloud Platform. To retrieve that key, we simply need to login to our Digital Ocean Control Panel then click on API, then click on Generate New Token and give it a name tick on both Read and Write. Then we'll get a long hex key, thats the <API-Token> now, simply replace it into the command above.
|
||||
|
||||
After running the above command, we can see in our Digital Ocean Droplet Panel that a droplet has been created with default configuration.
|
||||
|
||||
![DigitalOcean Droplet Panel](http://blog.linoxide.com/wp-content/uploads/2015/05/digitalocean-droplet-panel.png)
|
||||
|
||||
For ease and convenience, docker-machine deploys the droplet with default configuration choosing setting such as images that the VPS is based on we can override the default configuration as our need. We can do that by simply adding the flags respective to our need and requirement of the Droplet. Here are some flags for digitalocean that we can add to override the default configuration of the Docker Machine.
|
||||
|
||||
--digitalocean-image "ubuntu-14-04-x64" for Choosing Droplet Image
|
||||
--digitalocean-ipv6 enable to enable IPv6 Networking
|
||||
--digitalocean-private-networking enable to enable Private Networking
|
||||
--digitalocean-region "nyc3" to choose Region to deploy the Droplet
|
||||
--digitalocean-size "512mb" to select the RAM size and type of deployment.
|
||||
|
||||
If you are wanting to use docker-machine with other cloud providers and need to override the default configuration, we can run following command to get the list of flags for every platforms supported by Docker Machine by default.
|
||||
|
||||
# docker-machine create -h
|
||||
|
||||
### 3. Selecting Active Host ###
|
||||
|
||||
After deploying the droplet, we wanna run a docker container straight away but before that, we'll need to check whether the active host is the required machine or not. To see that, we can run the following command.
|
||||
|
||||
# docker-machine ls
|
||||
|
||||
![Docker Machine List](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-ls.png)
|
||||
|
||||
The active host can be identified by "*" in the ACTIVE column.
|
||||
|
||||
Now, if we need to switch the active host to the required machine, we can simply run the following command.
|
||||
|
||||
# docker-machine active linux-dev
|
||||
|
||||
**Note**: Here, linux-dev is the Machine name that we are wanting to make as ACTIVE and run Docker Container on top of it.
|
||||
|
||||
### 4. Running a Docker Container ###
|
||||
|
||||
Now, after selecting our active host, we'll wanna finally run a docker container out of the box. Now, to give it a test, we'll run a busybox container out of it by running docker run busybox command with echo hello world so that we can get the output of the container.
|
||||
|
||||
# docker run busybox echo hello world
|
||||
|
||||
Note: If you are trying to deploy a docker container using a 32 Bit Operating System running in the host, its good idea to use SSH to run the docker commands. So, you can simply skip this step and follow the SSH step.
|
||||
|
||||
### 5. SSH with Docker Machine ###
|
||||
|
||||
If we want to control over the machine or the droplet that we just deployed with Docker Machine, we can ssh into the server using docker-machine ssh as command.
|
||||
|
||||
# docker-machine ssh
|
||||
|
||||
![Docker Machine SSH](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-ssh.png)
|
||||
|
||||
Now, after ssh into the machine, we can run any docker containers into it. Here we'll run an nginx server into it.
|
||||
|
||||
# docker run -itd -p 80:80 nginx
|
||||
|
||||
After finishing up with SSH, we need to run exit to exit from the droplet or server.
|
||||
|
||||
# exit
|
||||
|
||||
### 5. Removing Hosts ###
|
||||
|
||||
In order to remove the active host and all its images, containers, we can use docker-machine rm command as shown below.
|
||||
|
||||
# docker-machine rm linux-dev
|
||||
|
||||
![Docker Machine Remove All](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-remove-machine.png)
|
||||
|
||||
To check whether the host has been removed or not, we can run docker-machine ls command.
|
||||
|
||||
# docker-machine ls
|
||||
|
||||
![Docker Machine Remove Check](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-remove-check.png)
|
||||
|
||||
### 6. Adding a host without a driver ###
|
||||
|
||||
We can add a host to Docker which only has a URL and no driver. It can be used an alias for an existing host, so we don’t have to type out the URL every time we run a Docker command.
|
||||
|
||||
$ docker-machine create --url=tcp://104.131.50.36:2376 custombox
|
||||
|
||||
### 7. Managing the Hosts ###
|
||||
|
||||
If you are finished working with the running docker, we can simply run **docker-machine stop** command to stop the whole hosts which are Active and if wanna start again, we can run **docker-machine start**.
|
||||
|
||||
# docker-machine stop
|
||||
# docker-machine start
|
||||
|
||||
You can also specify a machine name to stop or start using the host name as an argument.
|
||||
|
||||
$ docker-machine stop linux-dev
|
||||
$ docker-machine start linux-dev
|
||||
|
||||
### Conclusion ###
|
||||
|
||||
Docker Machine is really and awesome tool for deploying servers with Docker Container running. In this article we demostrated with Digital Ocean Platform but there are other platforms also available like Amazon Web Service, Google Cloud Computing and more which is supported by Docker Machine and includes driver APIs of them. It has made easy for fast and secure deployment of Docker Containers into several different Platforms with Docker Machine. As Docker Machine is still under Beta, so it is recommended not to use docker-machine in production. If you have any questions, suggestions, feedback please write them in the comment box below so that we can improve or update our contents. Thank you ! Enjoy :-)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-how-to/use-docker-machine-cloud-provider/
|
||||
|
||||
作者:[Arun Pyasi][a]
|
||||
译者:[goreliu](https://github.com/goreliu)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://linoxide.com/author/arunp/
|
||||
[1]:https://cloud.digitalocean.com/settings/applications
|
@ -0,0 +1,148 @@
|
||||
如何在云服务提供商的机器使用Docker Machine
|
||||
================================================================================
|
||||
大家好,今天我们来学习如何使用Docker Machine在各种云服务提供商的平台部署Docker。Docker Machine是一个可以帮助我们在自己的电脑、云服务提供商的机器以及我们数据中心的机器上创建Docker机器的应用程序。它为创建服务器、在服务器中安装Docker、根据用户需求配置Docker客户端提供了简单的解决方案。驱动API对本地机器、数据中心的虚拟机或者公用云机器都适用。Docker Machine支持Windows、OSX和Linux,并且提供一个独立的二进制文件,可以直接使用。它让我们可以充分利用支持Docker的基础设施的生态环境合作伙伴,并且使用相同的接口进行访问。它让人们可以使用一个命令来简单而迅速地在不同的云平台部署Docker容器。
|
||||
|
||||
|
||||
### 1. 安装Docker Machine ###
|
||||
|
||||
Docker Machine可以很好地支持每一种Linux发行版。首先,我们需要从Github网站下载最新版本的。这里我们使用curl来下载目前最新0.2.0版本的Docker Machine。
|
||||
|
||||
在64位操作系统运行:
|
||||
|
||||
# curl -L https://github.com/docker/machine/releases/download/v0.2.0/docker-machine_linux-amd64 > /usr/local/bin/docker-machine
|
||||
|
||||
在32位操作系统运行:
|
||||
|
||||
# curl -L https://github.com/docker/machine/releases/download/v0.2.0/docker-machine_linux-i386 > /usr/local/bin/docker-machine
|
||||
|
||||
下载最新版本的Docker Machine并将docker-machine文件放到了/usr/local/bin/后,添加执行权限:
|
||||
|
||||
# chmod +x /usr/local/bin/docker-machine
|
||||
|
||||
完成如上操作后,我们需要确认已经成功安装docker-machine了。可以运行如下命令检查,它会输出系统中docker-machine的版本:
|
||||
|
||||
# docker-machine -v
|
||||
|
||||
![Installing Docker Machine](http://blog.linoxide.com/wp-content/uploads/2015/05/installing-docker-machine.png)
|
||||
|
||||
另外机器上需要有docker命令,可以使用如下命令安装:
|
||||
|
||||
# curl -L https://get.docker.com/builds/linux/x86_64/docker-latest > /usr/local/bin/docker
|
||||
# chmod +x /usr/local/bin/docker
|
||||
|
||||
### 2. 创建机器 ###
|
||||
|
||||
在自己的Linux机器上安装好了Docker Machine之后,我们想要将一个docker虚拟机部署到云服务器上。Docker Machine支持几个流行的云平台,如igital Ocean、Amazon Web Services(AWS)、Microsoft Azure、Google Cloud Computing等等,所以我们可以在不同的平台使用相同的接口来部署Docker。本文中我们会使用digitalocean驱动在Digital Ocean的服务器上部署Docker,--driver选项指定digitalocean驱动,--digitalocean-access-token选项指定[Digital Ocean Control Panel][1]提供的API Token,命令最后的是我们创建的Docker虚拟机的机器名。运行如下命令:
|
||||
|
||||
# docker-machine create --driver digitalocean --digitalocean-access-token <API-Token> linux-dev
|
||||
|
||||
# eval "$(docker-machine env linux-dev)"
|
||||
|
||||
![Docker Machine Digitalocean Cloud](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-digitalocean-cloud.png)
|
||||
|
||||
**注意**: 这里linux-dev是我们将要创建的机器的名称。`<API-Token>`是一个安全key,可以在Digtal Ocean Control Panel生成。要找到这个key,我们只需要登录到我们的Digital Ocean Control Panel,然后点击API,再点击Generate New Token,填写一个名称,选上Read和Write。然后我们就会得到一串十六进制的key,那就是`<API-Token>`,简单地替换到上边的命令中即可。
|
||||
|
||||
运行如上命令后,我们可以在Digital Ocean Droplet Panel中看到一个具有默认配置的droplet已经被创建出来了。
|
||||
|
||||
![DigitalOcean Droplet Panel](http://blog.linoxide.com/wp-content/uploads/2015/05/digitalocean-droplet-panel.png)
|
||||
|
||||
简便起见,docker-machine会使用默认配置来部署Droplet。我们可以通过增加选项来定制我们的Droplet。这里是一些digitalocean相关的选项,我们可以使用它们来覆盖Docker Machine所使用的默认配置。
|
||||
|
||||
--digitalocean-image "ubuntu-14-04-x64" 是选择Droplet的镜像
|
||||
--digitalocean-ipv6 enable 是启用IPv6网络支持
|
||||
--digitalocean-private-networking enable 是启用专用网络
|
||||
--digitalocean-region "nyc3" 是选择部署Droplet的区域
|
||||
--digitalocean-size "512mb" 是选择内存大小和部署的类型
|
||||
|
||||
如果你想在其他云服务使用docker-machine,并且想覆盖默认的配置,可以运行如下命令来获取Docker Mackine默认支持的对每种平台适用的参数。
|
||||
|
||||
# docker-machine create -h
|
||||
|
||||
### 3. 选择活跃机器 ###
|
||||
|
||||
部署Droplet后,我们想马上运行一个Docker容器,但在那之前,我们需要检查下活跃机器是否是我们需要的机器。可以运行如下命令查看。
|
||||
|
||||
# docker-machine ls
|
||||
|
||||
![Docker Machine List](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-ls.png)
|
||||
|
||||
ACTIVE一列有“*”标记的是活跃机器。
|
||||
|
||||
现在,如果我们想将活跃机器切换到需要的机器,运行如下命令:
|
||||
|
||||
# docker-machine active linux-dev
|
||||
|
||||
**注意**:这里,linux-dev是机器名,我们打算激活这个机器,并且在其中运行Docker容器。
|
||||
|
||||
### 4. 运行一个Docker容器 ###
|
||||
|
||||
现在,我们已经选择了活跃机器,就可以运行Docker容器了。可以测试一下,运行一个busybox容器来执行`echo hello word`命令,这样就可以得到输出:
|
||||
|
||||
# docker run busybox echo hello world
|
||||
|
||||
注意:如果你试图在一个装有32位操作系统的宿主机部署Docker容器,使用SSH来运行docker是个好办法。这样你就可以简单跳过这一步,直接进入下一步。
|
||||
|
||||
### 5. SSH到Docker机器中 ###
|
||||
|
||||
如果我们想在机器或者Droplet上控制之前部署的Docker机器,可以使用docker-machine ssh命令来SSH到机器上:
|
||||
|
||||
# docker-machine ssh
|
||||
|
||||
![Docker Machine SSH](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-ssh.png)
|
||||
|
||||
SSH到机器上之后,我们可以在上边运行任何Docker容器。这里我们运行一个nginx:
|
||||
|
||||
# docker run -itd -p 80:80 nginx
|
||||
|
||||
操作完毕后,我们需要运行exit命令来退出Droplet或者服务器。
|
||||
|
||||
# exit
|
||||
|
||||
### 5. 删除机器 ###
|
||||
|
||||
删除在运行的机器以及它的所有镜像和容器,我们可以使用docker-machine rm命令:
|
||||
|
||||
# docker-machine rm linux-dev
|
||||
|
||||
![Docker Machine Remove All](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-remove-machine.png)
|
||||
|
||||
使用docker-machine ls命令检查是否成功删除了:
|
||||
|
||||
# docker-machine ls
|
||||
|
||||
![Docker Machine Remove Check](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-remove-check.png)
|
||||
|
||||
### 6. 在不使用驱动的情况新增一个机器 ###
|
||||
|
||||
我们可以在不使用驱动的情况往Docker增加一台机器,只需要一个URL。它可以使用一个已有机器的别名,所以我们就不需要每次在运行docker命令时输入完整的URL了。
|
||||
|
||||
$ docker-machine create --url=tcp://104.131.50.36:2376 custombox
|
||||
|
||||
### 7. 管理机器 ###
|
||||
|
||||
如果你已经让Docker运行起来了,可以使用简单的**docker-machine stop**命令来停止所有正在运行的机器,如果需要再启动的话可以运行**docker-machine start**:
|
||||
|
||||
# docker-machine stop
|
||||
# docker-machine start
|
||||
|
||||
你也可以使用如下命令来使用机器名作为参数来将其停止或启动:
|
||||
|
||||
$ docker-machine stop linux-dev
|
||||
$ docker-machine start linux-dev
|
||||
|
||||
### 总结 ###
|
||||
|
||||
Docker Machine是一个非常棒的工具,可以使用Docker容器快速地部署服务。文中我们使用Digital Ocean Platform作演示,但Docker Machine还支持其他平台,如Amazon Web Service、Google Cloud Computing。使用Docker Machine,快速、安全地在几种不同平台部署Docker容器变得很简单了。因为Docker Machine还是Beta版本,不建议在生产环境使用。如果你有任何问题、建议、反馈,请在下方的评论框中写下来,我们会改进或者更新我们的内容。谢谢!享受吧 :-)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-how-to/use-docker-machine-cloud-provider/
|
||||
|
||||
作者:[Arun Pyasi][a]
|
||||
译者:[goreliu](https://github.com/goreliu)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://linoxide.com/author/arunp/
|
||||
[1]:https://cloud.digitalocean.com/settings/applications
|
Loading…
Reference in New Issue
Block a user