linka-cloud / d2vm

Build Virtual Machine Image from Dockerfile or Docker image
Apache License 2.0
208 stars 31 forks source link

How to use a VM image as an EC2 instance? #39

Closed dray92 closed 1 month ago

dray92 commented 11 months ago

Followed these steps to attempt to use the image as an EC2 VM:

aws iam create-role --role-name vmimport --assume-role-policy-document file://trust-policy.json

cat trust-policy.json
{
   "Version": "2012-10-17",
   "Statement": [
      {
         "Effect": "Allow",
         "Principal": { "Service": "vmie.amazonaws.com" },
         "Action": "sts:AssumeRole",
         "Condition": {
            "StringEquals":{
               "sts:Externalid": "vmimport"
            }
         }
      }
   ]
}
aws ec2 import-snapshot --description "example image" --disk-container file://container.json

cat container.json
[
    {
        "Description": "Example image originally in QCOW2 format",
        "Format": "raw",
        "UserBucket": {
            "S3Bucket": "raw-images-debo-test",
            "S3Key": "ubuntu-debo.raw"
        }
    }
]

steps to build and push image:

d2vm build -f Dockerfile -o ubuntu-debo.qcow2 d2vm/examples/full

qemu-img convert ubuntu-debo.qcow2 ubuntu-debo.raw
aws s3 cp ubuntu-debo.raw s3://raw-images-debo-test
aws ec2 import-image --description "My test VM" --disk-containers file://containers.json

# to check progress
aws ec2 describe-import-image-tasks

neither of the steps of importing the snapshot or importing the image worked.

Adphi commented 11 months ago

I'm sorry, I don't have much experience with aws.

But I can help by following some standard debugging steps.

First,

d2vm build -f Dockerfile -o ubuntu-debo.qcow2 d2vm/examples/full
qemu-img convert ubuntu-debo.qcow2 ubuntu-debo.raw

You can do this in a single step using the following command (I expect build-args to have been supplied, otherwise you won't be able to connect to the vm):

d2vm build --build-arg [...] -f Dockerfile -o ubuntu-debo.raw d2vm/examples/full

Then, have you tried launching the image locally with qemu?

d2vm run qemu ubuntu-debo.raw

You will not be able to connect because your build command did not include a root password.

What is the result of the previous steps ?

Then you provide the commands but no output, so I have no idea what the errors are.

Adphi commented 1 month ago

I'm closing this issue as no response has been received.

Please feel free to reopen if necessary 😉