Search code examples
dockergoogle-compute-enginegoogle-container-registry

GCE doesn't deploy GCR image correctly


I have followed this guide from Google documentation in order to be able to push a custom Docker image to Google Container Registry and then be able to start a new GCE instance with this image. At first I wanted to try using an anaconda3 public image from docker hub without any modification (in order to test).

So here is the steps I have done so far after installing gcloud and docker:

  1. gcloud auth configure-docker -> configured docker with my gcloud crendentials
  2. docker pull continuumio/anaconda3 -> pulled the public image
  3. docker tag continuumio/anaconda3 eu.gcr.io/my-project-id/anaconda3 -> tagged the local image with the registry name as specified in the doc
  4. docker push eu.gcr.io/my-project-id/anaconda3 -> pushed the image to GCR

Good ! I am now able to see my image trough GCR interface, and also able to deploy it with GCE. I choose to deploy it with a f1-micro instance, Container-Optimized OS 67-10575.62.0 stable, 10 Go boot disk, Allow HTTP traffic, etc.

But when I connect with ssh to the freshly new created VM instance, I can't find anaconda3 librairies (which are supposed to be created in /opt/conda). Instead, I can see a /opt/google directory which makes me think that the image has not been deployed correctly and GCE is using a default image...

So I tried to check if the image was pushed correctly in GCR, so I decided to delete my local image and pull it once again from GCR:

  1. docker rmi -f eu.gcr.io/my-project-id/anaconda3
  2. docker pull eu.gcr.io/my-project-id/anaconda3:latest

I run the image

docker run -t -i eu.gcr.io/my-project-id/anaconda3

and I can see that everything is fine, I have anaconda3 installed correctly inside /opt/conda with all the toolts needed (Pandas, Numpy, Jupyter notebook, etc.)


I tried to find people with the same problem as me without any success... maybe I have done something wrong in my proccess ? Thanks !

TL;DR My problem is that I have pushed an anaconda3 image on Google GCR, but when I launch a virtual instance with this image, I do not have anaconda on it


Solution

  • It's normal that you can't find anaconda libraries installed directly on the GCE instance.

    Actually, when you choose to deploy a container image on a GCE VM instance, a Docker container is started from the image you provide (in your example, eu.gcr.io/my-project-id/anaconda3). The libraries are not installed on the host, but rather inside that container (run docker ps to see it, but normally it has the same name as your VM instance). If you run something like :

    docker exec -it <docker_container_name> ls /opt/conda
    

    Then you should see the anaconda libraries, only existing inside the container.

    When you run docker run -t -i eu.gcr.io/my-project-id/anaconda3, you're actually starting the container and running an interactive bash session inside that container (see the CMD here). That's why you can find anaconda libraries : you are inside the container!

    Containerization software (docker here) provides isolation between your host and your containers. I'll suggest you to read documentation about containerization, Docker and how to run containers on Container-Optimized OS.