github.com/hustcat/docker@v1.3.3-0.20160314103604-901c67a8eeab/docs/installation/cloud/cloud-ex-aws.md (about)

     1  <!--[metadata]>
     2  +++
     3  title = "Example: Manual install on cloud provider"
     4  description = "Example of a manual install of Docker Engine on a cloud provider, using Amazon Web Services (AWS) EC2. Shows how to create an EC2 instance, and install Docker Engine on it."
     5  keywords = ["cloud, docker, machine, documentation,  installation, AWS, EC2"]
     6  [menu.main]
     7  parent = "install_cloud"
     8  +++
     9  <![end-metadata]-->
    10  
    11  # Example: Manual install on cloud provider
    12  
    13  You can install Docker Engine directly to servers you have on cloud providers.  This example shows how to create an <a href="https://aws.amazon.com/" target="_blank"> Amazon Web Services (AWS)</a> EC2 instance, and install Docker Engine on it.
    14  
    15  You can use this same general approach to create Dockerized hosts on other cloud providers.
    16  
    17  ### Step 1. Sign up for AWS
    18  
    19  1. If you are not already an AWS user, sign up for <a href="https://aws.amazon.com/" target="_blank"> AWS</a> to create an account and get root access to EC2 cloud computers. If you have an Amazon account, you can use it as your root user account.
    20  
    21  2. Create an IAM (Identity and Access Management) administrator user, an admin group, and a key pair associated with a region.
    22  
    23      From the AWS menus, select **Services** > **IAM** to get started.
    24  
    25      See the AWS documentation on <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/get-set-up-for-amazon-ec2.html" target="_blank">Setting Up with Amazon EC2</a>. Follow the steps for "Create an IAM User" and "Create a Key Pair".
    26  
    27      If you are just getting started with AWS and EC2, you do not need to create a virtual private cloud (VPC) or specify a subnet. The newer EC2-VPC platform (accounts created after 2013-12-04) comes with a default VPC and subnet in each availability zone. When you launch an instance, it automatically uses the default VPC.
    28  
    29  ### Step 2. Configure and start an EC2 instance
    30  
    31  Launch an instance to create a virtual machine (VM) with a specified operating system (OS) as follows.
    32  
    33    1. Log into AWS with your IAM credentials.
    34  
    35        On the AWS home page, click **EC2** to go to the dashboard, then click **Launch Instance**.
    36  
    37        ![EC2 dashboard](../images/ec2_launch_instance.png)
    38  
    39        AWS EC2 virtual servers are called *instances* in Amazon parlance. Once you set up an account, IAM user and key pair, you are ready to launch an instance. It is at this point that you select the OS for the VM.
    40  
    41    2. Choose an Amazon Machine Image (AMI) with the OS and applications you want. For this example, we select an Ubuntu server.
    42  
    43        ![Launch Ubuntu](../images/ec2-ubuntu.png)
    44  
    45    3. Choose an instance type.
    46  
    47        ![Choose a general purpose instance type](../images/ec2_instance_type.png)
    48  
    49    4. Configure the instance.
    50  
    51      You can select the default network and subnet, which are inherently linked to a region and availability zone.
    52  
    53        ![Configure the instance](../images/ec2_instance_details.png)
    54  
    55    5. Click **Review and Launch**.
    56  
    57    6. Select a key pair to use for this instance.
    58  
    59      When you choose to launch, you need to select a key pair to use. Save the `.pem` file to use in the next steps.
    60  
    61  The instance is now up-and-running. The menu path to get back to your EC2 instance on AWS is: **EC2 (Virtual Servers in Cloud)** > **EC2 Dashboard** > **Resources** > **Running instances**.
    62  
    63  To get help with your private key file, instance IP address, and how to log into the instance via SSH, click the **Connect** button at the top of the AWS instance dashboard.
    64  
    65  
    66  ### Step 3. Log in from a terminal, configure apt, and get packages
    67  
    68  1. Log in to the EC2 instance from a command line terminal.
    69  
    70      Change directories into the directory containing the SSH key and run this command (or give the path to it as part of the command):
    71  
    72          $ ssh -i "YourKey" ubuntu@xx.xxx.xxx.xxx
    73  
    74      For our example:
    75  
    76          $ cd ~/Desktop/keys/amazon_ec2
    77          $ ssh -i "my-key-pair.pem" ubuntu@xx.xxx.xxx.xxx
    78  
    79      We'll follow the instructions for installing Docker on Ubuntu at https://docs.docker.com/engine/installation/ubuntulinux/. The next few steps reflect those instructions.
    80  
    81  2. Check the kernel version to make sure it's 3.10 or higher.
    82  
    83          ubuntu@ip-xxx-xx-x-xxx:~$ uname -r
    84          3.13.0-48-generic
    85  
    86  3. Add the new `gpg` key.
    87  
    88          ubuntu@ip-xxx-xx-x-xxx:~$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
    89          Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.jNZLKNnKte --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
    90          gpg: requesting key 2C52609D from hkp server p80.pool.sks-keyservers.net
    91          gpg: key 2C52609D: public key "Docker Release Tool (releasedocker) <docker@docker.com>" imported
    92          gpg: Total number processed: 1
    93          gpg:               imported: 1  (RSA: 1)
    94  
    95  4. Create a `docker.list` file, and add an entry for our OS, Ubuntu Trusty 14.04 (LTS).
    96  
    97          ubuntu@ip-xxx-xx-x-xxx:~$ sudo vi /etc/apt/sources.list.d/docker.list
    98  
    99      If we were updating an existing file, we'd delete any existing entries.
   100  
   101  5. Update the `apt` package index.
   102  
   103          ubuntu@ip-xxx-xx-x-xxx:~$ sudo apt-get update
   104  
   105  6. Purge the old repo if it exists.
   106  
   107      In our case the repo doesn't because this is a new VM, but let's run it anyway just to be sure.
   108  
   109          ubuntu@ip-xxx-xx-x-xxx:~$ sudo apt-get purge lxc-docker
   110          Reading package lists... Done
   111          Building dependency tree       
   112          Reading state information... Done
   113          Package 'lxc-docker' is not installed, so not removed
   114          0 upgraded, 0 newly installed, 0 to remove and 139 not upgraded.
   115  
   116  7.  Verify that `apt` is pulling from the correct repository.
   117  
   118          ubuntu@ip-172-31-0-151:~$ sudo apt-cache policy docker-engine
   119          docker-engine:
   120          Installed: (none)
   121          Candidate: 1.9.1-0~trusty
   122          Version table:
   123          1.9.1-0~trusty 0
   124          500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
   125          1.9.0-0~trusty 0
   126          500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
   127              . . .
   128  
   129      From now on when you run `apt-get upgrade`, `apt` pulls from the new repository.
   130  
   131  ### Step 4. Install recommended prerequisites for the OS
   132  
   133  For Ubuntu Trusty (and some other versions), it’s recommended to install the `linux-image-extra` kernel package, which allows you use the `aufs` storage driver, so we'll do that now.
   134  
   135          ubuntu@ip-xxx-xx-x-xxx:~$ sudo apt-get update
   136          ubuntu@ip-172-31-0-151:~$ sudo apt-get install linux-image-extra-$(uname -r)
   137  
   138  ### Step 5. Install Docker Engine on the remote instance
   139  
   140  1. Update the apt package index.
   141  
   142          ubuntu@ip-xxx-xx-x-xxx:~$ sudo apt-get update
   143  
   144  2. Install Docker Engine.
   145  
   146          ubuntu@ip-xxx-xx-x-xxx:~$ sudo apt-get install docker-engine
   147          Reading package lists... Done
   148          Building dependency tree       
   149          Reading state information... Done
   150          The following extra packages will be installed:
   151          aufs-tools cgroup-lite git git-man liberror-perl
   152          Suggested packages:
   153          git-daemon-run git-daemon-sysvinit git-doc git-el git-email git-gui gitk
   154          gitweb git-arch git-bzr git-cvs git-mediawiki git-svn
   155          The following NEW packages will be installed:
   156          aufs-tools cgroup-lite docker-engine git git-man liberror-perl
   157          0 upgraded, 6 newly installed, 0 to remove and 139 not upgraded.
   158          Need to get 11.0 MB of archives.
   159          After this operation, 60.3 MB of additional disk space will be used.
   160          Do you want to continue? [Y/n] y
   161          Get:1 http://us-west-1.ec2.archive.ubuntu.com/ubuntu/ trusty/universe aufs-tools amd64 1:3.2+20130722-1.1 [92.3 kB]
   162          Get:2 http://us-west-1.ec2.archive.ubuntu.com/ubuntu/ trusty/main liberror-perl all 0.17-1.1 [21.1 kB]
   163          . . .
   164  
   165  3. Start the Docker daemon.
   166  
   167          ubuntu@ip-xxx-xx-x-xxx:~$ sudo service docker start
   168  
   169  4. Verify Docker Engine is installed correctly by running `docker run hello-world`.
   170  
   171          ubuntu@ip-xxx-xx-x-xxx:~$ sudo docker run hello-world
   172          ubuntu@ip-172-31-0-151:~$ sudo docker run hello-world
   173          Unable to find image 'hello-world:latest' locally
   174          latest: Pulling from library/hello-world
   175          b901d36b6f2f: Pull complete
   176          0a6ba66e537a: Pull complete
   177          Digest: sha256:8be990ef2aeb16dbcb9271ddfe2610fa6658d13f6dfb8bc72074cc1ca36966a7
   178          Status: Downloaded newer image for hello-world:latest
   179  
   180          Hello from Docker.
   181          This message shows that your installation appears to be working correctly.
   182  
   183          To generate this message, Docker took the following steps:
   184          1. The Docker client contacted the Docker daemon.
   185          2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
   186          3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
   187          4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
   188  
   189          To try something more ambitious, you can run an Ubuntu container with:
   190          $ docker run -it ubuntu bash
   191  
   192          Share images, automate workflows, and more with a free Docker Hub account:
   193          https://hub.docker.com
   194  
   195          For more examples and ideas, visit:
   196          https://docs.docker.com/userguide/
   197  
   198  ## Where to go next
   199  
   200  _Looking for a quicker way to do Docker cloud installs and provision multiple hosts?_ You can use [Docker Machine](https://docs.docker.com/machine/overview/) to provision hosts.
   201  
   202    * [Use Docker Machine to provision hosts on cloud providers](https://docs.docker.com/machine/get-started-cloud/)
   203  
   204    * [Docker Machine driver reference](https://docs.docker.com/machine/drivers/)
   205  
   206  *  [Install Docker Engine](../index.md)
   207  
   208  * [Docker User Guide](../../userguide/intro.md)