This guide shows how to prepare a web service to run in a container on
Knative serving. It does not cover data migration.

## Identify the port your code is listening on

Your service should listen for requests on a specific port. You must identify
this port and [configure Knative serving to send request to the same port](https://docs.cloud.google.com/kubernetes-engine/enterprise/knative-serving/docs/configuring/containers.md.txt#command-line).

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](https://docs.cloud.google.com/kubernetes-engine/enterprise/knative-serving/docs/configuring/containers#command-line) to
`3000` in Knative serving.

Knative serving 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](https://docs.cloud.google.com/storage) or data storage such as
[Firestore](https://docs.cloud.google.com/firestore) or [Cloud SQL](https://docs.cloud.google.com/sql).

## Add a `Dockerfile`

In order to wrap your service in a container, you should use a Dockerfile to
define the operating environment. Read more about customizing your `Dockerfile`
on the [Developing your service](https://docs.cloud.google.com/kubernetes-engine/enterprise/knative-serving/docs/developing.md.txt#add-dockerfile)
page.

## Tune for concurrency and memory limits

Learn about [concurrency](https://docs.cloud.google.com/kubernetes-engine/enterprise/knative-serving/docs/concurrency.md.txt) in
Knative serving and how to optimize your services in
[development tips for tuning concurrency](https://docs.cloud.google.com/kubernetes-engine/enterprise/knative-serving/docs/tips/general.md.txt#tuning-concurrency).

Make sure your [memory limit](https://docs.cloud.google.com/kubernetes-engine/enterprise/knative-serving/docs/configuring/memory-limits.md.txt) is high enough
for your application to run, including capacity for any temporary file storage
your service requires.

## Send logs to stdout or stderr

Knative serving automatically uses Google Cloud Observability to aggregate and
review your logs, as described in the [logging page](https://docs.cloud.google.com/kubernetes-engine/enterprise/knative-serving/docs/logging.md.txt).