Docker Basics

Docker is a technology that allows you to build, run, test, and deploy distributed
applications that are based on Linux containers. Amazon ECS uses Docker images in task
definitions to launch containers on EC2 instances in your clusters. For Amazon ECS product
details, featured customer case studies, and FAQs, see the Amazon EC2 Container Service product detail
pages.

The documentation in this guide assumes that readers possess a basic understanding of what
Docker is and how it works. For more information about Docker, see What is Docker? and the Docker User Guide.

Installing Docker

Docker is available on many different operating systems, including most modern Linux
distributions, like Ubuntu, and even Mac OSX and Windows. For more information about how
to install Docker on your particular operating system, go to the Docker installation
guide.

You don't even need a local development system to use Docker. If you are using Amazon EC2
already, you can launch an Amazon Linux instance and install Docker to get started.

To install Docker on an Amazon Linux instance

Launch an instance with the Amazon Linux AMI. For more information, see Launching an Instance in
the Amazon EC2 User Guide for Linux Instances.

(Optional) Sign up for a Docker Hub Account

Docker uses images that are stored in repositories to launch containers with. The most
common Docker image repository (and the default repository for the Docker daemon) is
Docker Hub. Although you don't need a Docker Hub account to use Amazon ECS or Docker, having
a Docker Hub account gives you the freedom to store your modified Docker images so you
can use them in your ECS task definitions.

Docker Hub offers public and private registries. You can create a private registry on
Docker Hub and configure Private Registry
Authentication on your ECS container instances to use your private images in
task definitions.

Create a Docker Image and
Upload it to Docker Hub

Amazon ECS task definitions use Docker images to launch containers
on the container instances in your clusters. In this section, you create a
Docker image of a simple PHP web application, and test it on your local system or EC2
instance, and then push the image to your Docker Hub registry
so you can use it in an ECS task definition.

To create a Docker image of a PHP web application

Install git and use it to clone the simple PHP application
from your GitHub repository onto your system.

Examine the Dockerfile in this folder. A Dockerfile is a manifest that
describes the base image to use for your Docker image and what you want
installed and running on it. For more information about Dockerfiles, go to the
Dockerfile
Reference.

This
Dockerfile uses the Ubuntu 12.04 image. The RUN instructions
update the package caches, install some software packages for the web server and
PHP support, and then add your PHP application to the web server's document
root. The EXPOSE instruction exposes port 80 on the
container, and the CMD instruction starts the web
server.

Output from the Apache web server is displayed in the terminal window.
You can ignore the "Could not reliably determine the server's
fully qualified domain name" message.

Open a browser and point to the server that is running Docker and hosting your
container.

If you are using an EC2 instance, this is the Public
DNS value for the server, which is the same address you
use to connect to the instance with SSH. Make sure that the security
group for your instance allows inbound traffic on port 80.

If you are using docker-machine on a Windows or Mac
computer, find the IP address of the VirtualBox VM that is hosting
Docker with the docker-machine ip command,
substituting machine-name with the name of
the docker machine you are
using.

$ docker-machine ip machine-name
192.168.59.103

You should see a web page running the simple PHP app.

Stop the Docker container by typing Ctrl+c.

Next Steps

After the image push is finished, you can use the
my-dockerhub-username/amazon-ecs-sample
image in your Amazon ECS task definitions, which you can use to run tasks with.

To register a task definition with the amazon-ecs-sample
image

Examine the simple-app-task-def.json file in the
ecs-demo-php-simple-app
folder.

This
task definition JSON file specifies two containers, one of which uses the
amazon-ecs-sample image. By default, this image is pulled
from the Amazon Docker Hub repository, but you can change the
amazon repository defined above to your own
repository if you want to use the
my-dockerhub-username/amazon-ecs-sample
image you pushed earlier.