You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/workloads.md
+58Lines changed: 58 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,64 @@ faas-cli new --list
44
44
45
45
Custom binaries can also be used as a function. Just use the `dockerfile` language template and replace the `fprocess` variable with the command you want to run per request. If you would like to pipe arguments to a CLI utility you can prefix the command with `xargs`.
46
46
47
+
### Running an existing Docker image on OpenFaaS
48
+
49
+
Let's take a Node.js app which listens on traffic using port 3000, and assume that we can't make any changes to it.
50
+
51
+
You can view its Dockerfile and code at: [alexellis/expressjs-k8s](https://github.com/alexellis/expressjs-k8s/) and the image is published to the Docker Hub at: `alexellis2/service:0.3.6`
52
+
53
+
Start by creating a new folder:
54
+
55
+
```bash
56
+
mkdir -p node-service/
57
+
```
58
+
59
+
Write a custom Dockerfile `./node-service/Dockerfile`:
60
+
61
+
```Dockerfile
62
+
# Import the OpenFaaS of-watchdog
63
+
FROM openfaas/of-watchdog:0.7.2 as watchdog
64
+
65
+
# Add a FROM line from your existing image
66
+
FROM alexellis2/service:0.3.6
67
+
68
+
# Let's say that the image listens on port 3000 and
69
+
# that we can't change that easily
70
+
ENV http_port 3000
71
+
72
+
# Install the watchdog from the base image
73
+
COPY --from=watchdog /fwatchdog /usr/bin/
74
+
75
+
# Now set the watchdog as the start-up process
76
+
# Along with the HTTP mode, and an upstream URL to
77
+
# where your HTTP server will be running from the original
78
+
# image.
79
+
ENV mode="http"
80
+
ENV upstream_url="http://127.0.0.1:3000"
81
+
82
+
# Set fprocess to the value you have in your base image
83
+
ENV fprocess="node index.js"
84
+
CMD ["fwatchdog"]
85
+
```
86
+
87
+
Now create a stack.yml at the root directory `./stack.yml`:
0 commit comments