-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
26ac8d8
docs: Add Docker docs to FF
grant ce5c8fd
docs: Add Docker docs to FF
grant 80a2c3e
Update docs/docker.md
grant 10843f1
Merge branch 'master' into grant_docs
grant 0e8e9a6
doc: Remove GKE option
grant 898fb02
docs: Update gcloud
grant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
node_modules/ | ||
build/ | ||
/docs/ | ||
.coverage/ | ||
npm-debug.log | ||
.nyc_output | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# 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 | ||
``` | ||
|
||
## Configure gcloud | ||
|
||
To use Docker with gcloud, (configure the Docker credential helper](https://cloud.google.com/container-registry/docs/advanced-authentication): | ||
|
||
```sh | ||
gcloud auth configure-docker | ||
``` | ||
|
||
## Deploy a Container | ||
|
||
You can deploy your containerized function to Cloud Run 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 | ||
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). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
E.g., to keep the current instructions, add
gcloud auth configure-docker
.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 added the configure docker command.