Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create an AWS AMI from a Docker image?

Tags:

I have a Docker image in my AWS ECR which I want to convert to an AWS AMI for creating an instance with the environment.

Reason for trying to use an AMI over a Docker container

I had to run computationally intensive ML tasks in my Docker container inside an m4.xlarge instance on some text files. However, with Docker, the CPU utilization of the instance is reaching 100% and the script is getting killed pre-maturely.

However, it is running fine in the same instance from outside of Docker.


So, I want to move to AMI's from Docker, however I also want to leverage Docker for the environment creation and the speed of testing which it enables in my local.

So, is it possible to create an AMI out of the Docker image which I test and deploy to my ECS registry?

like image 432
Dawny33 Avatar asked Jul 17 '17 11:07

Dawny33


People also ask

How do I convert a Docker image to AMI?

Turning an AMI into a Docker ImageOpen your AWS Console and search for the AMI you'd like to image. The Block Device Mapping for /dev/sda1 shows the EBS Snapshot containing the root filesystem for the AMI. Find that snapshot in the AWS Console, right-click and select “Create Volume”.

Is a Docker image the same as an AMI?

A Docker image is a template that contains instructions for creating, deploying, and provisioning Docker containers. AMIs are images containing instructions for launching an instance.

Can we create our own AMI in AWS?

You can create an AMI using the AWS Management Console or the command line. The following diagram summarizes the process for creating an AMI from a running EC2 instance. Start with an existing AMI, launch an instance, customize it, create a new AMI from it, and finally launch an instance of your new AMI.


2 Answers

There is no direct way to create an AWS AMIs out of docker image although there is an opensource tool which can create/build AWS AMIs out of a docker file but only supported instructions are ENV, RUN, COPY and ADD, other instructions will just be ignored.

Open-source Tool for Building AWS AMI from Docker file

https://github.com/mickep76/docker-build-ami

https://pypi.python.org/pypi/docker-build-ami/0.1.3

So if you are really interested in trying out go ahead with creating a proper docker file from your docker image. For that you can refer following links

Is it possible to extract the Dockerfile from a docker container

How to generate a Dockerfile from an image?

like image 66
karthik v Avatar answered Sep 19 '22 20:09

karthik v


It would seem that there is a problem or misconfiguration with the docker image or docker. You mention the instance runs the same script outside of docker without a problem? Then better create an AMI of the instance with the running script and you don't need docker at all. Having a script running within docker could at most mean the docker configuration limits CPU, but not that the host CPU goes to 100% and kills the script. You should try running a docker container with the same image, but on a sleep10000 run, so you can go within the container, run the script of interest and see what is failing.

like image 40
Efren Avatar answered Sep 17 '22 20:09

Efren