Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
  • Overview
  • Transcript

2.2 EC2 Container Services: Docker on Amazon

With Docker becoming more and more popular, it’s good to see that AWS offers Docker support through an easy-to-use but flexible interface. In this lesson, I will show you how to set up a WordPress site using Docker containers on EC2 Container Services.

Related Links

2.2 EC2 Container Services: Docker on Amazon

Hi! Welcome back to Explore Amazon Web Services. In this lesson, we're going to look at Amazon's Docker infrastructure, called EC2 Container Services. Docker became massively popular over the last two years. And because of that, Amazon introduced a service dedicated to making easy to run Docker containers on the Amazon computer cloud. If you aren't familiar with Docker, I suggest you check out the Deploy Arrays Application with Docker course, by Josimata here on Tuts+, as I'm not going to go very deep into Docker right now. With all the new services on AWS, they provide you with a getting started section, and an introduction video to get you going. After that, you're ready to create your first task, as they call it. A task is the overall container of something you want to accomplish, like running a WordPress site, in our case. To run this task, we need Docker containers to run the software. Those contain single components that can be linked together in a modular fashion. First, we need a container to run our WordPress. In our case, it is running an Apache web server, with the WordPress files already present. We can also choose an image to use. This image will be pulled from DockerHub, and gladly, WordPress already provides such an image. Next, we can choose the memory and CPU requirements, and make it essential for our task. This means if the container stops, the task does too. Since it's a web server, we need port mapping from the container to the host, so we can reach it from the web. We are going to map port 80 to port 80 on the host. You can also add shared volumes and mount them to the file system, but we don't need that here. What we do need is a linking with a second container I'm going to create in a minute. WordPress needs a MySQL database, and because of the multi-array of Tucker, it isn't included in the WordPress container. So, we are going to link to MySQL container as MySQL to our WordPress container. Since the name and link name match, we don't have to use a colon and commit the container name. Now that the WordPress container is set up, we can create the MySQL container. We can, again, choose the MySQL image from DockerHub. Every Docker image has a default, so we just use the latest one by omitting the version. We also need to set memory and CPUs, and make it essential. Everything else we can leave blank. Since the Docker container gets linked, we don't need to expose any ports. The only thing that is mandatory, that the MySQL image is setting a root password as an environment variable. I'm going to be super creative right now and choose password. After setting up our containers, we can review the generated JSON file that reflects our settings. You could use that to generate a Docker configuration automatically. In the next step, you have to choose if you want to create the service, or just run a task once. Creating a service means that it tries to always keep your desired number of tasks running. If one stops, it recovers and starts a new one. There is also an option to use a load balancer to handle load between tasks. Every Docker container needs a host, so we have to create an EC2 instance, but luckily the setup wizard helps us with that. We can choose the instance type and key pair here. It also creates a basic security group which opens part 80 automatically. You will also have to choose or create an instance role, which allows the EC2 instance to access your container services and manage your tasks. After everything is set up, we can create our service. AWS uses cloud formation, a service to manage your resources using templates to create the EC2 instance. When this is complete, you can see your cluster, which can contain multiple services, tasks, and instances. Somehow easy to container services, fail to run the task on the first try, because the instance is not set up at the point. But eventually, it will run, and you can watch the state of every container inside the task. When you look at the WordPress container in detail, it shows you the MySQL link, and the network bindings, which also contain a link to the instance that exposes your WordPress site. Clicking on it shows us that the service is running correctly, and showing the WordPress installer. If you want to change a task, you have to update its definition. Definitions are versioned, and you can choose the revision you want to use. Let's up our CPUs and memory for the WordPress container. As an example, after saving, the task has a revision number of two. But when we go back to view our cluster, we see that revision one is still running. We can change our service to run revision two. As you can see, the deployments page shows the primary deployment, which has no running tasks, and the old deployment, which has one. To expedite the upgrade process, I'm going to stop the old task and let the service use the new one. Remember, when you upgrade the servers and have no extended volume, your data will be lost. This is how you run Docker containers on AWS. In the next lesson, we will look at Lamda, a service to run codes based on events. See you there.

Back to the top