Log In

How to run a Docker container in the cloud: 5 best solutions

How to run a Docker container in the cloud: 5 best solutions
Cloud
25.03.2024
6 min read
Hostman Team
Technical writer

Containerization greatly simplifies the software development process, and the biggest advantage of using containers is their portability. However, running a container on the cloud can lead to some complications. Of course, you can deploy containers on cloud provider servers using an IaaS (infrastructure as a service) model, but you will have to administer these servers. To avoid this, cloud providers came up with the CaaS (Containers as a Service) model.

How to run a Docker container in the cloud without configuring the infrastructure

Containers as a service, or CaaS, is a modern model that allows developers to run their Docker containers directly in the cloud without having to deploy infrastructure, including orchestration tools (Docker Swarm, Kubernetes, OpenStack, etc.) and software cluster management software. The main benefits of using CaaS are as follows:

  • Reduced costs. There is no need to maintain the infrastructure to run your Docker container, which means running CaaS is faster and cheaper.

  • Flexibility. In most cases, you can easily move from cloud to cloud or even back to on-premises infrastructure, freeing you from being tied to a specific provider.

  • Speed. Because the underlying infrastructure is already provisioned, you don't have to worry about managing and maintaining the hardware your Docker containers will run on, meaning you can deploy them faster.

  • Security. CaaS not only makes it easier to run applications, but also improves security as most CaaS solutions include vulnerability scanning.

There are some important factors to consider when choosing the right CaaS solution. For example, the ability to work with multi-container applications, supported storage functions and file formats, and the technologies used to ensure data safety. Each solution has specific features and limitations, which we will now examine in detail.

Amazon Elastic Container Service (ECS)

Amazon ECS is a scalable container orchestration platform for running and managing containers in a clustered environment. You can choose the containers to run, how many containers to run, how they communicate, and the resources your containers use. There are two ways to use ECS: through EC2 instances or with Fargate.

In the first case, containers will be deployed on EC2 instances (virtual machines) created for the cluster. This gives you full control over the type of EC2 instance you use. For example, if your container is used for machine learning and is GPU-centric, you can run a virtual machine optimized for that task. The only downside to this solution is that you will be responsible for patching, managing network security, and scaling.

With the AWS Fargate model, you don't have to worry about managing EC2 instances. Fargate directly manages the underlying servers needed to run Docker containers by pre-configuring a cluster. Thus, you will relieve yourself of the need to manage infrastructure. However, only one network mode (awsvpc) is still supported, which may limit your ability to implement a number of tasks.

AWS Lambda

This is a serverless service from AWS where you submit code in various languages (Java, Go, C#, Python, Powershell, Node.js, Ruby), and Amazon runs it in the corresponding Lambda interface. Lambda functions are primarily called by connecting them to AWS API Gateway, which exposes the functions as REST API calls. Initially, AWS Lambda did not support containerization applications, but since December 2020, this service from Amazon can create a Docker image and run containers up to 10 GB in size.

Using Lambda to run a Docker container in the cloud will give you, first of all, good scalability: Lambda can create up to 500 new instances every minute automatically. However, since Lambda is AWS's own serverless technology, you may have to face challenges when moving to another cloud provider. Among other restrictions, we note that Lambda functions can be executed for no more than 15 minutes, which means you can forget about long-running tasks.

AWS App Runner

Launched in May 2021, AWS App Runner allows you to move your web application to the cloud without worrying about scaling or the infrastructure associated with the application. Essentially, it just launches ECS with Fargate to run your container, but you don't need to configure anything related to Fargate to get started. AWS App Runner can run in build mode, pulling code from your GitHub repository and building the application on any commits you push to master/main. It can also run in container mode, where you connect your container registry (though only AWS ECR is currently supported) and specify your image.

The main advantage of AWS App Runner is that it is easy to set up and provides an easy way to run a web application in the cloud. Among the disadvantages, we note that the build mode only supports the Python and Node.js runtimes. Build mode also doesn't have integration with AWS CodeCommit or other version control systems, meaning you'll only have to use GitHub. Finally, the application cannot communicate with private VPCs.

Azure Container Instances (ACI)

This solution from Microsoft offers:

  • persistent storage by connecting an Azure file share to a container;

  • managing groups of containers that share a host, local network, or storage;

  • full control over the instance on which your Docker container runs;

  • increasing the computing power of the GPU to the required values.

Let's also add that since the container is located in your virtual network, it can communicate with other resources in it. The only drawback of ACI is that calling Docker containers is only supported from the registry.

Google Cloud Run

Google's CaaS solution is built on the Knative platform based on Kubernetes. As with AWS App Runner, you can specify a container registry or repository containing your application code. Google Cloud Run's advantages include Google Secret Manager support and code support in many programming languages, including Go, Python, Java, Node.js, and Ruby. Among the shortcomings, we note only a limited number of regions compared, for example, with Azure and AWS services.

Conclusion

While there are some differences in the solutions from Amazon, Microsoft, and Google, they share a common goal of making it easier for developers to run Docker containers in a cloud orchestration environment while maintaining the flexibility needed to support a wide range of workloads. Moreover, each solution has its own limitations that must be taken into account when choosing a solution for your tasks.


Share

Our clouds are ready for your data

It's the perfect time to migrate to Hostman!