Building a Docker Image

To deploy your application on Google Container 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:

Building and deploying a Docker image

To package your application into a Docker image and push that image to Container Registry for deployment:

  1. 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"]
    

  2. Give your Docker image a name, using the following naming convention:

      gcr.io/[YOUR_PROJECT_ID]/[YOUR_APPLICATION_NAME]
    

    Replace [YOUR_PROJECT_ID] with your project ID and [YOUR_APPLICATION_NAME] with the name of your application. Do not include the square brackets.

  3. Build your Docker image locally, using the following docker command:

      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.

  4. 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!

What's next

Send feedback about...

Cloud Endpoints with OpenAPI