To deploy your application on Kubernetes Engine or Google Compute Engine using containers, you need to package your application code into a Docker image. This tutorial presents the steps to build a Docker image for your application.
Before you begin
Do the following before starting this tutorial:
Create a project
Familiarize yourself with building a Docker image using DockerFile. A Dockerfile describes the packages required for your application and how to install these packages.
Install the Google Cloud SDK.
Building and deploying a Docker image
To package your application into a Docker image and push that image to Container Registry for deployment:
Create a DockerFile.
You can use the following DockerFile as a reference:
FROM gcr.io/google_appengine/python RUN apt-get update && \ apt-get install -y python2.7 python-pip && \ apt-get clean && \ rm /var/lib/apt/lists/*_* ADD . /app WORKDIR /app RUN pip install -r requirements.txt ENTRYPOINT ["gunicorn", "-b", ":8080", "main:app"]
Give your Docker image a name, using the following naming convention:
Replace [YOUR_PROJECT_ID] with your project ID and [YOUR_APPLICATION_NAME] with the name of your application. Do not include the square brackets.
Build your Docker image locally, using the following
docker build -t [DOCKER_IMAGE_NAME] -f [DOCKERFILE_LOCATION] [APPLICATION_FILE_PATH]
Replace [DOCKER_IMAGE_NAME], [DOCKERFILE_LOCATION] and [APPLICATION_FILE_PATH] with values that correspond to your Docker image name, the path to your Dockerfile, and application files respectively. Do not include the square brackets.
Push the Docker image to the Container Registry using the following command:
gcloud docker -- push [DOCKER_IMAGE_NAME]
Replace [DOCKER_IMAGE_NAME] with your Docker image name. Do not include the square brackets.
That's it, your image can now be deployed!