5

What is the difference between an AWS EC2 instance and a docker container instance? When should I use one over the other?

nz_21
  • 6,140
  • 7
  • 34
  • 80
  • The answers to [How is Docker different from a virtual machine?](https://stackoverflow.com/questions/16047306/how-is-docker-different-from-a-virtual-machine?rq=1) cover a lot of this ground; in the EC2 case Amazon is hosting the VM. – David Maze Oct 22 '20 at 23:12

3 Answers3

3

When you get an EC2 instance it will provide the base installation of that specific operating system with some additional AWS packages installed such as the SSM Agent.

There are then AMIs that are prepared for specific usecases such as SQL Server, or in this case pre-configured with AWS Orchestration services (either ECS or EKS) which have the usecase software installed.

If you're not familiar with Docker I would suggest running it in your local environment first so that you can become familiar with it. Yes people have been moving towards containers and serverless but you need to ensure you are able to support this in production.

With containers being deployed you will need to understand the orchestration layer that you're using. It's very easy to see containers as an alternative to a virtualisation layer, but there are many differences to how these operate.

Take a look at the What is Docker? page for further explanations.

Chris Williams
  • 32,215
  • 4
  • 30
  • 68
0

The AMI is a pre-configured template to launch an EC2 instance. EC2 stands for Elastic Container Service. To clarify, EC2 provides service for containers but is not a container itself. EC2 is a pre-configured virtual machine or a cloud server that can run containers like Docker.

Basically, you can use both.

You would use an AMI to launch your EC2 instance and then build your Docker image to run your applications. You can have multiple Docker images and containers on the same EC2 instance. EC2 will have an operating system, Linux, Ubuntu, Redhat, etc. Docker will use whatever OS and kernel on EC2 and creates an isolated environment for each application like a package.

There is also a way to control versions on Docker Hub. Similar to Github, you can update your Docker builds and push to the hub from your local machine then ssh into your EC2 instance and pull the latest Docker build.

Docker makes it easy to move your application to different machines: localhost to EC2, my computer to coworkers, or AWS to Azure.

0

EC2 and Docker containers can both run applications in a computing environment, but they serve different purposes and have distinct characteristics.

EC2: EC2 provided a VM with its own OS. Provides strong isolation between instances. Usually will take more CPU/RAM and well suited for monolith architecture. More maintenance with patching, access control. More expensive. OS updates can interfere with certain applications. Supports persistent data (in EBS volumes)

Docker: Runs in a VM or AWS provides serverless option (Fargate). Less maintenance specially with fargate. Dedicated ram/cpu. Lightweight and portable since running on same docker image. Easy (automatic) to scale in AWS environment. Does not support persistent data (attached volume will be lost when fargate is stopped, however, data can be saved in S3 or docker can be run in EC2 as well)

Both are used heavily, it really depends on your use case.

skzi
  • 340
  • 3
  • 14