This is the same port you would use when invoking your service on your local
machine. For example, if to test your code you open localhost:3000, then set
the container port to
3000 in Cloud Run.
Cloud Run defaults to sending requests to 8080.
The value of the port to which requests are sent is always available in the
PORT environment variable. It is a best practice for your code to listen on
the value defined by the PORT environment variable if possible.
Remove reliance on local filesystem for persistent storage
Check your application code for reliance on local filesystems, and replace it
with file storage on Cloud Storage or data storage such as
Firestore or Cloud SQL.
Add a Dockerfile
In order to wrap your service in a container, you should use a Dockerfile to
define the operating environment. The
build and deploy quickstart
shows some basic Dockerfiles you can use to get started.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-25 UTC."],[],[],null,["# Migrate an existing web service\n\nThis guide shows how to prepare a web service to run in a container on\nCloud Run. It does not cover data migration.\n\nIdentify the port your code is listening on\n-------------------------------------------\n\nYour service should listen for requests on a specific port. You must identify\nthis port and [configure Cloud Run to send requests to the same port](/run/docs/configuring/services/containers#command-line).\n\nThis is the same port you would use when invoking your service on your local\nmachine. For example, if to test your code you open `localhost:3000`, then [set\nthe container port](/run/docs/configuring/services/containers#command-line) to\n`3000` in Cloud Run.\n\nCloud Run defaults to sending requests to `8080`.\nThe value of the port to which requests are sent is always available in the\n`PORT` environment variable. It is a best practice for your code to listen on\nthe value defined by the `PORT` environment variable if possible.\n\nRemove reliance on local filesystem for persistent storage\n----------------------------------------------------------\n\nCheck your application code for reliance on local filesystems, and replace it\nwith file storage on [Cloud Storage](/storage) or data storage such as\n[Firestore](/firestore) or [Cloud SQL](/sql).\n\nAdd a `Dockerfile`\n------------------\n\nIn order to wrap your service in a container, you should use a Dockerfile to\ndefine the operating environment. The\n[build and deploy quickstart](/run/docs/quickstarts#build-and-deploy-a-web-service)\nshows some basic Dockerfiles you can use to get started.\n\nRead more about customizing your `Dockerfile` on the [Developing your service](/run/docs/developing#add-dockerfile)\npage.\n\nTune for concurrency and memory limits\n--------------------------------------\n\nLearn more about [how concurrency works](/run/docs/about-concurrency)\nthen optimize your service concurrency support in [development tips for tuning concurrency](/run/docs/tips#tuning-concurrency)\n\nMake sure your [memory limit](/run/docs/configuring/services/memory-limits) is high enough\nfor your application to run, including capacity for any temporary file storage\nyour service requires.\n\nSend logs to stdout, stderr, or /var/log\n----------------------------------------\n\nCloud Run automatically uses Google Cloud Observability to aggregate and\nreview your logs, as described in the [logging page](/run/docs/logging)."]]