When deploying to Flexible Environment using the default runtime (e.g. python), we just need to specify different app.yaml files with different entrypoint: values.

But what would the 'best practice' for custom runtimes be for this case?

Multiple Dockerfile's with different CMD values?

But that would mean that each service needs to be built individually. Maybe have a 'base' Dockerfile and image to speed up the build?


Copying my answer to a question on Stack Overflow https://stackoverflow.com/questions/49388615/multiple-services-with-different-dockerfiles-on-gae-flexible/58119935#58119935

tl;dr: build a separate docker image, push it to GCR, deploy using that image.

Specify a custom runtime. Build the image locally, tag it, and push it to Google Container Registry (GCR) then, deploy your service, specifying a custom service file, and specifying the remote image on GCR using the --image-url option.

Here's an example that accomplishes different entrypoints in 2 services that share the same code: ...this is assuming that the "flex" and not "standard" app engine offering is being used.

lets say you have a project called my-proj with a default service that is not important and a second service called queue-processor which is using much of the same code from the same directory. Create a separate dockerfile for it called QueueProcessorDockerfile and a separate app.yaml called queue-processor-app.yaml to tell google app engine what i want to happen.


FROM node:10
# Create app directory
WORKDIR /usr/src/app
COPY package.json ./
COPY yarn.lock ./
RUN npm install -g yarn
RUN yarn
# Bundle app source
COPY . .
CMD [ "yarn", "process-queue" ]

*of course i have a "process-queue" script in my package.json queue-processor-app.yaml

runtime: custom
env: flex
... other stuff...
  1. build and tag the docker image Check out googles guide here -> https://cloud.google.com/container-registry/docs/pushing-and-pulling docker build -t eu.gcr.io/my-proj/queue-processor -f QueueProcessorDockerfile .
  2. push it to GCR docker push eu.gcr.io/my-proj/queue-processor
  3. deploy the service, specifying which yaml config file google should use, as well as the image url you have pushed gcloud app deploy queue-processor-app.yaml --image-url eu.gcr.io/my-proj/queue-processor

Regardless of using a default flexible runtime or a custom one you always need an app.yaml for every service in your app. The difference is in the content of the app.yaml file (apart from the Dockerfile needed for custom runtimes). From Building Custom Runtimes:

To create a custom runtime you need:

  • An app.yaml file that describes your application's runtime configuration.
  • A Dockerfile that configures the runtime environment. In many cases, this can be just one line specifying a base image.


Create an app.yaml file

You must use an app.yaml configuration file with the following settings:

runtime: custom
env: flex


Create a Dockerfile

The Dockerfile is always named Dockerfile and should be placed in the same directory with the corresponding app.yaml file.

The actual content of a service's dockerfile depends on what the service is supposed to do. Theoretically the Dockerfiles contents could even be identical - there is no risk of collisions since they must be located in different directories (since their name is fixed). This is in line with the recommended dir structure of a multi-service/module app (the image is now gone, but it was captured in this older SO post)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.