Google Cloud VM Image to docker image

10/19/2019

I have a Google Cloud VM that installed with my application. The installation step is completed and I:

  1. Turned off the VM instance.
  2. Exported the disk to disk image called MY_CUSTOM_IMAGE_1

My wish now is to use MY_CUSTOM_IMAGE_1 as the starting image of my docker image build. For building the images I'm using Google Cloud Build.

My docker file should look like this:

FROM MY_CUSTOM_IMAGE_1 AS BUILD_ENV
...

When I tried to use this image I got the build error:

ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: exit status 1
ERROR
pull access denied for MY_CUSTOM_IMAGE_1, repository does not exist or may require 'docker login'
Step 1/43 : FROM MY_CUSTOM_IMAGE_1 AS BUILD_ENV

The reason is that VM images are not the same as Docker images.

Is this possible to make this transform (GCP VM Image -> Docker image), without external tools (outside GCP, like "docker private repositories")?

Thanks!

-- No1Lives4Ever
docker
google-cloud-build
google-cloud-platform
google-kubernetes-engine

2 Answers

10/19/2019

If you know all the installed things on your VM (and all the commands), do the same thing in a Dokerfile. Use as base image, the same OS version as your current VM. Perform some tests and it should be quickly equivalent.

If you have statefull files in your VM application, it's a little bit more complex, you have to mount a disk in your container and to update your application's configuration to write in the correct mounted folder. It's more "complex" but there is tons of example on internet!

-- guillaume blaquiere
Source: StackOverflow

10/19/2019

No, this is not possible without a tool to extract your application out of the virtual machine image and recreate in a container. To the best of my knowledge, there is no general-purpose tool that exists.

There is a big difference between a container image and a virtual machine image. Container images do not have an operating system, virtual machine images are a complete operating system and device data. The two conceptually are similar, but extremely different in how they are implemented at the software and hardware level.

-- John Hanley
Source: StackOverflow