Create a custom runtime app in the App Engine flexible environment
Region ID
TheREGION_ID is an abbreviated code that Google assignsbased on the region you select when you create your app. The code does notcorrespond to a country or province, even though some region IDs may appearsimilar to commonly used country and province codes. For apps created after February 2020,REGION_ID.r is included in App Engine URLs. For existing apps created before this date, the region ID is optional in the URL.
Custom runtimeslet you build apps that run in an environment defined by aDockerfile. By using aDockerfile, you can use languages and packages that are not part of theGoogle Cloud and use the same resources and tooling that are used in theApp Engine flexible environment.
In this quickstart, annginx web server is launched toApp Engine using a custom runtime.
Before you begin
Before running the sample app in this quickstart, you need to set up yourenvironment and create a new Google Cloud project for App Engine:
Create a new Google Cloud project by using the Google Cloud console:
Open the Google Cloud console:
ClickCreate Project and then name your new Google Cloud project.
Enable billing in your new Google Cloud project by creating a newbilling account or setting an existing one:
Download and install the Google Cloud CLI and then initialize thegcloud CLI:
Run the following
gcloudcommand to create an App Engineapplication and specify in which geographicalregion that you want your appto run:gcloud app create- Due tochanges in the defaultbehavior for how Cloud Build uses service accounts in new projects, andsecure-by-defaultorganization policy changes, you might need to grant additional roles toyour deploying service account. For more information on granting specific roles,see thetroubleshooting guide.
App Engine Locations
App Engine isregional, which means the infrastructure that runs your apps islocated in a specific region, and Google manages it so that it is availableredundantly acrossall of the zones within that region.
Meeting your latency, availability, or durability requirements are primaryfactors for selecting the region where your apps are run. You can generallyselect the region nearest to your app's users, but you should considerthelocations where App Engine is availableas well as thelocations of the otherGoogle Cloud products and services that your app uses. Using servicesacross multiple locations can affect your app's latency as well as itspricing.
You cannot change an app's region after you set it.
Note: Two locations, which are calledeurope-west andus-central in App Engine commands and in the Google Cloud console,are calledeurope-west1 andus-central1, respectively,elsewhere in Google documentation.If you already created an App Engine application, you can view itsregion by doing one of the following:
Run the
gcloud app describecommand.Open theApp Engine Dashboard in the Google Cloud console.The region appears near the top of the page.
Download the Hello World app
Choose one of the following to download the Hello World sample app fromGitHub, to your local machine:
Clone the Hello World sample app from the following repository:
git clone https://github.com/GoogleCloudPlatform/appengine-custom-runtimes-samplesDownload thesample as a .zip file and then extract it to a local directory.
Navigate to the
nginxdirectory where the sample code is located, forexample:cd appengine-custom-runtimes-samples/nginx
Running Hello World on your local machine
You can test the sample app bydownloading and installingDocker, and then runningthe Hello World container on your local machine.
There are no App Engine specific steps here so you can test the sampleapp using the tools and approach that you prefer.
Deploying Hello World to App Engine
When you are ready to deploy the sample app to App Engine, perform thefollowing steps:
From the directory where your
app.yamlandDockerfileare located, runthe following command:gcloud app deployLearn about theoptional flags.
To see your app running at
https://PROJECT_ID.REGION_ID.r.appspot.com, run the followingcommand to launch your browser:gcloud app browse
Commongcloud command flags
- Include the
--versionflag to specify an ID that uniquely identifies that version of your app, otherwise one is generated for you. Example:--version [YOUR_VERSION_ID] - Include the
--projectflag to specify an alternate Google Cloud project ID to what you initialized as the default in thegcloudtool. Example:--project [YOUR_PROJECT_ID]
Example:
gcloud app deploy --version pre-prod-5 --project my-sample-app
To learn more about deploying your app from the command line, seeTesting and Deploying Your App. For a list of all the command flags, see thegcloud app deployreference.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
What's next
Learn more about Dockerfiles at theDockerfile reference.
For information on how to create your own custom runtime, seeBuilding Custom Runtimes.
Code review
Hello World is the simplest possible App Engine app, as it createsa single container that runs only one service and one version. This sectiondescribes each of the app's files in detail.
app.yamlSpecifies the configuration of the app. The
app.yamlfile must reside inthe same directory as theDockerfilefile.runtime:customenv:flexThe
runtime: customentry tells App Engine to look for aDockerfilethat will define your runtime's image andenv: flexspecifies that you are deploying to the flexible environment.For more information, see the
app.yamlreference.DockerfileDefines the set of instructions that are used to create the Docker image forthe sample app's container. The
Dockerfilefile must reside in the samedirectory as theapp.yamlfile. ThisDockerfileinstalls the nginx webserver and copies some basic configuration:# The standard nginx container just runs nginx. The configuration file added# below will be used by nginx.FROMnginx# Copy the nginx configuration file. This sets up the behavior of nginx, most# importantly, it ensure nginx listens on port 8080. Google App Engine expects# the runtime to respond to HTTP requests at port 8080.COPYnginx.conf/etc/nginx/nginx.conf# create log dir configured in nginx.confRUNmkdir-p/var/log/app_engine# Create a simple file to handle health checks. Health checking can be disabled# in app.yaml, but is highly recommended. Google App Engine will send an HTTP# request to /_ah/health and any 2xx or 404 response is considered healthy.# Because 404 responses are considered healthy, this could actually be left# out as nginx will return 404 if the file isn't found. However, it is better# to be explicit.RUNmkdir-p/usr/share/nginx/www/_ah &&\echo"healthy" >/usr/share/nginx/www/_ah/health# Finally, all static assets.ADDwww//usr/share/nginx/www/RUNchmod-Ra+r/usr/share/nginx/wwwThe FROM command builds a base image using the official docker image for the nginx web server.
Using this
Dockerfile, your container image will contain nginx and all content in thewww/directory is available to your application.
The Hello World sample app also includes annginx.conffile, which contains the basic nginx configuration information, as well was theindex.htmlfile, which serves as the root page for the nginx web server.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.