Skip to Content

Build docker container in GCP container builder

Posted on 2 mins read

If you need to build docker container and want to save your laptop battery, you can easily build your container in GCP container builder.

You will need to have gcloud on your system.

Authorize the gcloud command-line tool to access your project:

gcloud auth login

Configure your project for the gcloud tool, where [PROJECT_ID] is your GCP project ID that you created or selected in the previous section:

gcloud config set project [PROJECT_ID]

and now you can build your image using GCP container builder

gcloud builds submit --tag[PROJECT_ID]/quickstart-image .

you run this image locally you need to configure Docker to use your Container Registry credentials when interacting with Container Registry (you are only required to do this once):

gcloud auth configure-docker

and now you can pull your image and run

docker run[PROJECT_ID]/quickstart-image

You also can use build config file

- name: ''
  args: [ 'build', '-t', '$PROJECT_ID/quickstart-image', '.' ]
- '$PROJECT_ID/quickstart-image'

and if you want to use cache to speed up your builds you can add

'--cache-from', '$PROJECT_ID/quickstart-image',

to your config

- name: ''
  args: [
            '-t', '$PROJECT_ID/quickstart-image',
            '--cache-from', '',
- '$PROJECT_ID/quickstart-image'

and don’t forget to pull newly builded image

docker pull[PROJECT_ID]/quickstart-image

use separate folder for build, because gcloud will compress it and send to cloud

comments powered by Disqus