Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a docker image/container from EC2 AMI

I am very new to docker and am trying to import my AWS EC2 AMI into a docker image. The image is a m2 linux image.

I have also setup a private docker hub(artifactory) to which I intend to push the image and make it available for consumption. What are the steps for importing AMI into docker image without starting from a base image and updating.

Pointers to any explanation would work too.

like image 857
user1795516 Avatar asked Mar 29 '15 00:03

user1795516


People also ask

How do I create a Docker image from 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”.

Can we create a Docker image of a EC2 instance?

In this section, you create a Docker image of a simple web application, and test it on your local system or Amazon EC2 instance, and then push the image to the Amazon ECR container registry so you can use it in an Amazon ECS task definition. Create a file called Dockerfile .

Is AMI same as Docker image?

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.


2 Answers

Here is how I did it.

  • On source AMI locate root volume snapshot id in the description

/dev/sda1=snap-eb79b0b1:15:true:gp2

  • Launch instance with public Ubuntu 14.04 AMI

  • Create volume from snapshot snap-eb79b0b1 (in the same region that the instance runs).

  • Attach volume to the instance as /dev/sdf

  • mount volume to /mnt

mount /dev/xvdf /mnt

(or)

mount /dev/xvdf1 /mnt

  • install docker

https://docs.docker.com/engine/installation/ubuntulinux/

  • import docker image from mounted root volume

tar -c -C /mnt/ . | docker import - appcimage-master-1454216413

  • run

docker run -t -i 6d6614111fcb03d5ca79541b8a23955202dfda74995d968b5ffb5d45c7e68da9 /bin/bash

like image 177
user2153517 Avatar answered Oct 11 '22 10:10

user2153517


Docker can create an image from a tar file using the docker import command. From the documentation:

Usage: docker import URL|- [REPOSITORY[:TAG]]  Create an empty filesystem image and import the contents of the tarball  (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz) into it, then optionally tag it. 

So you should be able to create a tar archive from your AMI image and then feed that to docker.

like image 26
larsks Avatar answered Oct 11 '22 11:10

larsks