|
| 1 | +# Developing functions with Docker Compose |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This examples shows you how to develop a Cloud Function locally with Docker Compose, including live reloading. |
| 6 | + |
| 7 | +## Install `docker-compose`: |
| 8 | +https://docs.docker.com/compose/install/ |
| 9 | + |
| 10 | +## Start the `docker-compose` environment: |
| 11 | + |
| 12 | +In this directory, bring up the `docker-compose` environment with: |
| 13 | +``` |
| 14 | +docker-compose up |
| 15 | +``` |
| 16 | + |
| 17 | +You should see output similar to: |
| 18 | + |
| 19 | +``` |
| 20 | +Building function |
| 21 | +[+] Building 7.0s (10/10) FINISHED |
| 22 | + => [internal] load build definition from Dockerfile 0.0s |
| 23 | + => => transferring dockerfile: 431B 0.0s |
| 24 | + => [internal] load .dockerignore 0.0s |
| 25 | + => => transferring context: 2B 0.0s |
| 26 | + => [internal] load metadata for docker.io/library/python:latest 0.6s |
| 27 | + => [1/5] FROM docker.io/library/python@sha256:7a93befe45f3afb6b337 0.0s |
| 28 | + => [internal] load build context 0.0s |
| 29 | + => => transferring context: 2.11kB 0.0s |
| 30 | + => CACHED [2/5] WORKDIR /func 0.0s |
| 31 | + => [3/5] COPY . . 0.0s |
| 32 | + => [4/5] RUN pip install functions-framework 4.7s |
| 33 | + => [5/5] RUN pip install -r requirements.txt 1.1s |
| 34 | + => exporting to image 0.4s |
| 35 | + => => exporting layers 0.4s |
| 36 | + => => writing image sha256:99962e5907e80856af6b032aa96a3130dde9ab6 0.0s |
| 37 | + => => naming to docker.io/library/docker-compose_function 0.0s |
| 38 | +
|
| 39 | +Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them |
| 40 | +Recreating docker-compose_function_1 ... done |
| 41 | +Attaching to docker-compose_function_1 |
| 42 | +function_1 | * Serving Flask app 'hello' (lazy loading) |
| 43 | +function_1 | * Environment: production |
| 44 | +function_1 | WARNING: This is a development server. Do not use it in a production deployment. |
| 45 | +function_1 | Use a production WSGI server instead. |
| 46 | +function_1 | * Debug mode: on |
| 47 | +function_1 | * Running on all addresses. |
| 48 | +function_1 | WARNING: This is a development server. Do not use it in a production deployment. |
| 49 | +function_1 | * Running on http://172.21.0.2:8080/ (Press CTRL+C to quit) |
| 50 | +function_1 | * Restarting with watchdog (inotify) |
| 51 | +function_1 | * Debugger is active! |
| 52 | +``` |
| 53 | +function_1 | * Debugger PIN: 162-882-413 |
| 54 | + |
| 55 | +## Call your Cloud Function |
| 56 | + |
| 57 | +Leaving the previous command running, in a **new terminal**, call your functions. To call the `hello` function: |
| 58 | + |
| 59 | +```bash |
| 60 | +curl localhost:8080/hello |
| 61 | +``` |
| 62 | + |
| 63 | +You should see output similar to: |
| 64 | + |
| 65 | +```terminal |
| 66 | +Hello, World! |
| 67 | +``` |
0 commit comments