In this short article, I list the steps you need to follow in order to publish a Docker image to the Google Container Registry(GCR) in the Google Cloud Platform.
Pre-requisites
- Docker installed
- GCloud SDK
- User or service account with access required to push to GCR.
Steps to push docker image to GCR
Create Dockerfile
In a previous article on how to install Tensorflow with Docker, I showed you how to create a Dockerfile that extends the default Tensorflow image:
Let’s use that Tensorflow Docker image as the base container, and let’s publish this image to Google’s Container Registry:
FROM tensorflow/tensorflow:latest-gpu-jupyter
RUN pip install jupyterlab
Build and tag Image with docker build
docker build -t codemental/tensorflow .
Now I am going to assume that you want to publish to GCR directly from your Google account.
Login to GCloud
First, we log in:
gcloud auth login
If you would like to use instead a service account then we should call gcloud auth activate-service-account:
gcloud auth activate-service-account ACCOUNT --key-file=KEY-FILE
Docker Registry Login with Google Cloud
In order to push an image to GCR with Docker we run:
gcloud auth configure-docker
Tagging Docker Image
And then we give an appropriate tag to our image:
docker tag codemental/tensorflown gcr.io/<gcp-project-id>/tensorflown:0.1
Pushing Docker Image to gcr.io
To push to GCR.IO we simply have to do:
docker push gcr.io/<gcp-project-id>/tensorflown:0.1