Google Cloud: Building Containers with Dockerfile and Cloud Build

Share At:


Cloud Build is a service that executes your builds on Google Cloud Platform’s infrastructure. Cloud Build can import source code from a variety of repositories or cloud storage spaces, execute a build to your specifications, and produce artifacts such as Docker containers or Java archives.

Building Containers with DockerFile and Cloud Build

We can write build configuration files to provide instructions to Cloud Build as to which tasks to perform when building a container. These build files can fetch dependencies, run unit tests, analyses and more.

In this task, we will create a DockerFile and use it as a build configuration script with Cloud Build. We will also create a simple shell script ( which will represent an application inside the container.

  1. Ensure that below API’s have been enabled:

Cloud Build

Container Registry

In the Google Cloud Console, on the Navigation menu > click APIs & Services. Click Enable APIs and Services. In the Search for APIs & Services BoxType the above mentioned API’sIf Disabled, Enable The above two API’s.

2. On the Google Cloud Console title bar, click Activate Cloud Shell. When prompted, click Continue.

3. Create file using the your favorite text editor.

sudo vi

4. The file should look like below:

5. Also Create a “Dockerfile” file using a text editor. The Dockerfile should look like below:

6. The Instructions in the Dockerfile has below meaning:

7. In Cloud Shell, run the following command to make the script executable.

sudo chmod +x

8. In Cloud Shell, run the following command to build the Docker container image in Cloud Build:

gcloud builds submit — tag${GOOGLE_CLOUD_PROJECT}/quickstart-image .

Don’t miss the dot (“.”) at the end of the command. The dot specifies that the source code is in the current working directory at build time.

When the build completes, your Docker image is built and pushed to Container Registry.

Validating Newly Created Images in the Container Registry and Downloading Docker Image.

  1. In the Google Cloud Console, on the Navigation menu , click Container Registry > Images. The quickstart-image Docker image appears in the list.

2. At this stage, Running “Docker Images” Command will not show any Image on the system.

3. Use “docker pull” command to download the image.

docker pull–0cd3114364e3/quickstart-image

4. Validate that the Image has been downloaded to your machine and is ready for use.

This Concludes our tutorial for Building Containers with Dockerfile and Cloud Build.

Happy Learning !!!

Share At:
0 0 votes
Article Rating
Notify of
Oldest Most Voted
Inline Feedbacks
View all comments
4 days ago

I may need your help. I’ve been doing research on gate io recently, and I’ve tried a lot of different things. Later, I read your article, and I think your way of writing has given me some innovative ideas, thank you very much.

23 days ago

Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

Vytvorit osobní úcet

I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

Back To Top

Contact Us