Creating a Dockerfile

Let's begin with the first step of creating our gcloud Docker setup.

The first step of any Docker setup is to write its Dockerfile. In the Dockerfile, we’ll specify all the things we need in our container. There are three basic steps to always consider:

  • Make sure your container is running Ubuntu.
  • All frameworks required for your setup are installed in the Dockerfile.
  • Any code you need to run is copied into the container.

Dockerfile

Below, we have provided a basic Dockerfile for gcloud. We’ll go through it step-by-step.

Press + to interact
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y curl apt-transport-https ca-certificates gnupg
RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
RUN apt-get update && apt-get install -y google-cloud-sdk
  • FROM ubuntu:20.04 - Specifies the base image of our container. The ubuntu images are officially supported on Educative. However, other Debian images can also work.

  • apt-get update && apt-get install -y curl... - Installs a few prerequisite packages through simple apt-get install commands.

  • Lines 5 - 9: These are the official steps for installing gcloud. We use RUN to execute them.

Rule of thumb: The installation commands for any framework can be found all over the internet. The trick is to simply copy those commands into your Dockerfile.

Tarball

Once the Dockerfile is ready, you need to compress it into a tarball in order to upload it to your course.

tar -czpf gcloud.tar.gz Dockerfile

This creates a tarball named gcloud.tar.gz. You can find the file below:

gcloud.tar.gz

Uploading the Tarball

This is where you integrate your Docker setup into your course. Navigate to the main course editor page and find the Docker Container section:

The Change Dockerfile button lets you upload the tarball. Click on Save on the top-right to begin the building process! Once the image is built successfully, you will receive the following prompt:


We are almost at the finish line. Head to the next lesson to start using Google Cloud on Educative!