-
Notifications
You must be signed in to change notification settings - Fork 167
Docs: Add Docker Tutorial Doc #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
26ac8d8
ce5c8fd
80a2c3e
10843f1
0e8e9a6
898fb02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
node_modules/ | ||
build/ | ||
/docs/ | ||
.coverage/ | ||
npm-debug.log | ||
.nyc_output | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Run a Function in a Docker Container | ||
|
||
To run your function in a container, create a `Dockerfile` with the following contents: | ||
|
||
```Dockerfile | ||
# Use the official Node.js 10 image. | ||
# https://hub.docker.com/_/node | ||
FROM node:10 | ||
# Create and change to the app directory. | ||
WORKDIR /usr/src/app | ||
# Copy application dependency manifests to the container image. | ||
# A wildcard is used to ensure both package.json AND package-lock.json are copied. | ||
# Copying this separately prevents re-running npm install on every code change. | ||
COPY package.json package*.json ./ | ||
# Install production dependencies. | ||
RUN npm install --only=production | ||
# Copy local code to the container image. | ||
COPY . . | ||
# Run the web service on container startup. | ||
CMD [ "npm", "start" ] | ||
``` | ||
|
||
Start the container locally by running `docker build` and `docker run`: | ||
|
||
```sh | ||
docker build -t helloworld . && docker run --rm -p 8080:8080 helloworld | ||
``` | ||
|
||
Send requests to this function using `curl` from another terminal window: | ||
|
||
```sh | ||
curl localhost:8080 | ||
# Output: Hello, World | ||
``` | ||
|
||
## Deploy a Container | ||
|
||
You can deploy your containerized function to Cloud Run or any Knative-based environment by following the [Cloud Run quickstart](https://cloud.google.com/run/docs/quickstarts/build-and-deploy). | ||
|
||
Use the `docker` and `gcloud` CLIs to build and deploy a container to Cloud Run, replacing the project id `$GOOGLE_CLOUD_PROJECT` and image name `helloworld`: | ||
|
||
```sh | ||
docker build -t gcr.io/$GOOGLE_CLOUD_PROJECT/helloworld . | ||
docker push gcr.io/$GOOGLE_CLOUD_PROJECT/helloworld | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note docker push requires some extra steps to get docker authenticating with GCP. In fact, if you use Cloud Build you don't need to get docker working locally at all. Here are some Cloud Run-specific docs on build options There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we want to change these steps? Do we want to link the build options? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on your needs, pick Cloud Build or Docker and include mostly bare steps here, linking to that page for more context/options? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. E.g., to keep the current instructions, add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added the configure docker command. |
||
gcloud beta run deploy helloworld --image gcr.io/$GOOGLE_CLOUD_PROJECT/helloworld --region us-central1 | ||
``` | ||
|
||
If you want even more control over the environment, you can [deploy your container image to Cloud Run on GKE](https://cloud.google.com/run/docs/quickstarts/prebuilt-deploy-gke). With Cloud Run on GKE, you can run your function on a GKE cluster, which gives you additional control over the environment (including use of GPU-based instances, longer timeouts and more). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cloud Run or Cloud Run on GKE. Other knative instances are managed with
kubectl
or in the futurekn
. Instructions for knative in that case will also need a service.yaml.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would you like me to say instead of Cloud Run?
Does Cloud Run not include Cloud Run on GKE?
Can you suggest a change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for Cloud Run only: https://cloud.google.com/run/docs/quickstarts/build-and-deploy
This shows how to build and deploy an existing container image to Cloud Run on GKE: https://cloud.google.com/run/docs/quickstarts/prebuilt-deploy-gke
Deploying to Knative anywhere
https://knative.dev/docs/install/getting-started-knative-app/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the mention of Cloud Run on GKE.