zhu difeng - Fotolia


How to deploy a Docker container to the cloud

Docker is highly portable and widely available across all major cloud platforms, including AWS and Microsoft Azure, but it's important to properly plan your container deployment.

Docker is a popular container engine that provides a way to easily deploy and manage containers. Here, we look at some tips for how to deploy a Docker container in popular cloud environments.

By itself, Docker is essentially a single instance of an application-level virtualization platform. It also removes the application/OS dependencies and enables multiple applications to run on one Docker instance.

The underlying OS can be any of a number of Linux-based OSes. Most cloud providers offer some form of optimized base OS, such as RocketOS, JeOS or Alpine Linux. These OSes are lightweight and provide almost instant deployment capability. Depending on the cloud provider, you might be able to choose among multiple base OSes to run your containers on.

Before you begin

High availability (HA) is important for many business applications, and you should take the time to understand the difference between containers and VMs. Containers don't offer built-in HA, which means they might not be right for every application. Instead, many organizations build HA into the application itself, designing it specifically for a container-based environment.

Other important factors include planning for intrasystem communication. No matter which platform you use, you should use an internal network for management communication and avoid accidentally exposing management ports to the internet.

The history of containers

As you would with VMs, be sure to size your Docker hosts appropriately. Too big and you'll end up paying for more than you use. Too small and the applications won't perform well.

Be careful about using Docker images from unknown sources and public registries. Signed vendor-provided images are usually more trustworthy. Many cloud providers offer access to a private registry.

Docker deployment basics

Neither AWS nor Microsoft Azure offers stand-alone instances of Docker-optimized hosts. However, they both offer Kubernetes clusters that provide easy-to-deploy infrastructure. This entails deploying VMs that participate in the Kubernetes cluster and provide resilience. Essentially, Kubernetes does all the heavy lifting for you.

For those just looking to deploy single instances, the way forward is to create a standard VM and deploy the Docker infrastructure on top of the host. Depending on which cloud provider you choose, the deployment steps vary slightly.

First, create a new VM with enough resources for the container instances that will run on it.

I started by deploying a standard Ubuntu VM. Once deployed, with the public interface, I strongly recommend you use public key authentication, because a publicly exposed Secure Socket Shell (SSH) port can be a significant security risk.

Use an SSH client -- for example, PuTTY -- to connect to the bare host, and then install Docker using the following command:

Sudo apt-get install docker.io -y

Once installed, test it using the well-known cowsay application. Then, deploy the application using the following command:

docker run docker/whalesay cowsay Hi from TechTarget

This gets you started, but your instance still requires some configuration to expose the ports – or, rather, connect them so data can pass from the public IP address to the Docker image.

Deploy a Docker container to Azure

In most cases, it's not worth it to create your own hosts. Use the web interface or the Azure command-line interface to deploy the Docker instance as a service. In most cases, using Azure Container Service is cheaper and more efficient than creating your own hosts.

If you're willing to invest a bit of time and get the jump on implementation, you can set up a Kubernetes cluster with minimal effort.

However, it might make more sense to use the Azure Web App container service. This Microsoft service is useful because it removes the management requirement that comes with standing up your own cluster.

Microsoft Azure provides several great features, but you should learn to use tags first. You can use tagging in a variety of situations, such as to differentiate between releases and versions. Although it might seem a bit tricky, consistent tagging is worth its weight in gold.

Depending on your needs, you might want to create an IP reservation. This approach incurs an hourly cost, but it enables you to reserve a specific IP address. If a host is deleted or recreated and its external IP address is lost, access to that IP will be lost. Reservations, like the name suggests, enable you to reserve an IP address with the cloud provider.

Deploy a Docker container to AWS

Don't replicate the functionality that AWS already provides. Depending on the requirements, a lot of infrastructure is available as a shared service and is cheaper than building the resource from scratch. Amazon provides the AWS container registry for convenient storage of Docker images.

Be careful when using tags. On most platforms, pulling an image without specifying the version will result in the service using the latest image. If you don't specify the version, the next pull request could pull a different version, which could result in multiple instances running in the environment -- which can cause problems.

Dig Deeper on Containers and virtualization

Software Quality
App Architecture
Cloud Computing
Data Center