Docker 1.13 has recently been released and what I realized is that there are no good CloudFormation templates available. So I created my own CloudFormation template which creates an EC2 instance based on Ubuntu AMI and installs Docker.
If you just want to play around with Docker (without any installation) have a look at this awesome project by my fellow Docker CaptainMarcos Nils.
Basic VPC setup
Amazon WorkSpaces running Windows, and Docker CLI. An Amazon EC2 instance with Docker daemon running, listening for external traffic on a specific network interface, or all network interfaces (0.0.0.0). This can be a Windows or Linux host, depending on your application requirements.
First, we create a VPC which is a virtual network inside AWS. This helps us to isolate our EC2 instances and give them private IP addresses. Part of the VPC are subnets where each one is bound to an Availability Zone. Subnets can either be public or private. Public subnets route direct to the Internet and wherever private subnets can’t route to the Internet. To give instances in private subnets access to the Internet a NAT gateway which does the network translation needs to be created.
- Amazon Elastic Container Service (Amazon ECS) is the Amazon Web Service you use to run Docker applications on a scalable cluster. In this tutorial, you will learn how to run a Docker-enabled sample application on an Amazon ECS cluster behind a load balancer, test the sample application, and delete your resources to avoid charges.
- My goal: keep the installation as clean as possible. Run anything inside Docker containers. Especially the development environments. I work for many clients. I often encounter situations where I need multiple versions of the same software. Docker is of great help. But one of my favorite tools, the AWS CLI v1, was not working perfectly inside.
I highly recommend the CloudFormation templates that have been built by Andreas and Michael Wittig. These templates are available on GitHub and you can choose from several of templates. I picked one that supports three different Availability Zones.
SSH via Bastion Host
Next, I’d like to create a bastion host to reduce the attack surface. The advantage is that the ssh port does not have to be open to the public on all our instances but only on the bastion host. From there you can then jump to all other instances.
There are two ways how you can ssh into the machines. The first option is to upload an existing key pair and reference this name in the
KeyName parameter while creating the next stacks.
The second option is to add your public key to your IAM user. If this is done, the
IAMUserSSHAccess parameter needs to be set to true while creating the next stacks.
Install Docker Linux
The bastion host stack needs an addition parameter
ParentVPCStack to retrieve some output parameters from the VPC stack.
If you later want to ssh into your instance, first ssh into the bastion host and forward our key. From the bastion host, you can ssh into the Docker instance that we create later. (The IPs can be found on the AWS Console)
As the last step in our VPC setup, we’ve to create a NAT gateway in order to route traffic from instances in a private subnet to the internet.
Now we have our basic setup and we can proceed with installing Docker.
The whole stack template can be downloaded from https://github.com/pgarbe/containers_on_aws/blob/master/ubuntu/stack.yaml. It needs the parameters
ParentSSHBastionStack. In addition, the parameter for your chosen ssh access should be provided.
Aws Lightsail Install Docker
There are some additional parameters with default values which can also be overwritten:
|InstanceType||The instance type for the EC2 instance||t2.micro|
|DesiredInstances||The number of EC2 instances||1|
|SubnetsReach||Should the instances have direct access to the Internet or do you prefer private subnets with NAT?||Public|
|DockerVersion||Specifies the version of the Docker engine||1.13.0|
|DockerPreRelease||Specifies if an experimental version of Docker Engine should be used||false|
Containers can be started by adding another Command in the template which runs the
docker run command.
This example shows how to install Docker on AWS. It is secure, immutable and provides all the configuration as code.
Prerequisite for this:
- Launch an EC2 Linux Instance on AWS. For more details click here
- Connect to an instance using Putty.
Install Docker on the EC2 Instance
Aws Install Docker Daemon
- Update the installed packages and package cache on your instance by running the below command:
sudo yum update -y ( On linux instance apt-get doesn’t work , so you have to use the yum tool)
2. [ec2-user ~]$ sudo yum install -y docker
3. [ec2-user ~]$ sudo service docker start
Starting cgconfig service: [ OK ]
Starting docker: [ OK ]
4. Add the
ec2-user to the
docker group so you can execute Docker commands without using
[ec2-user ~]$ sudo usermod -a -G docker ec2-user
5. docker info
In some cases, you may need to reboot your instance to provide permissions for the
ec2-userto access the Docker daemon. Try rebooting your instance if you see the following error:
Install Docker Mac
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
Aws Install Docker Ec2
Docker is installed successfully. Isn’t it very easy to install docker ?
Comments are closed.