0

我一直在嘗試使用AWS's Import/Export將Docker映像轉換爲VMDK文件以創建AWS AMI。對於:AWS導入/導出任務的磁盤驗證失敗

  1. 我已經使用this guide創建從我DockerFile的.img文件。現在

  2. ,我使用這個命令:VBoxManage convertfromraw --format VMDK disk.img disk.vmdk.img文件轉換成.vmdk文件,如IMG格式,是由AWS服務不支持。

然而,當我運行導入/導出服務,它給了我這個錯誤:

"StatusMessage": "ClientError: Disk validation failed [Unsupported VMDK File Format]" 

這有什麼,我做錯了我的轉換過程?

回答

0

我接觸就同一問題的AWS支持人員。他們的回答如下:

Unfortunately, importing a Docker image is not supported by VMIE. Since a Docker image is not a fully-virtualized OS, you would not be able to boot into this image even if the import was successful.


There is a much simpler solution by running user-data. As far as the code running inside a container is concerned, there isn't a difference between containers or VM's. The code thinks its running on a regular OS. So instead of creating the docker container with the Dockerfile, you can use a user-data script to do the same things on an instance. For example, with ADD in a Dockerfile, it takes files and writes them to the container. We can pull this file from, say S3, and copy it wherever on the instance is needs to go. It will go in the same place that it lives in the container. The RUN directives in a docker file will map 1-to-1 with a user-data script, since these are simply commands. For the CMD directive, we can simply run that process via user-data. Docker volumes are irrelevant, since we have access to the full storage of the instance, so you can ignore the creation of volumes and simply write wherever any files need to go. In summary, your user-data script will replace the Dockerfile for bootstrapping your instance and running your application. Instead of Dockerfile syntax, you will use Bash syntax. Look below for an example script that mimics your Dockerfile.

#! /bin/bash 
pip install --upgrade --user awscli 
sudo aws s3 cp s3://example-bucket/hello/
sudo chmod +x /hello /hello 

Here is a breakdown of what the script is doing:

  1. Makes sure the aws cli is installed

  2. Pulls the file "hello" from an S3 bucket, and writes it to '/'

  3. Makes sure the file "hello" is executable

  4. Executes hello This is essentially what a Dockerfile does in a container, however instead of pulling from S3, it pulls it from the location of the Dockerfile. After adding your file to S3, you can easily pull it in a user-data script. Running this, you won't even need to create a custom AMI, as the bootstrapping is done on instance after bootup. To select the appropriate OS, you can launch a QuickStart Ubuntu AMI and add this user-data script. Additionally, you can continue testing with Docker without issue, you just need to make sure the file "hello" is in sync between your Docker location and the S3 bucket. You can use the S3 Sync command to accomplish this.