> For the complete documentation index, see [llms.txt](https://jahentao.gitbook.io/openfass/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jahentao.gitbook.io/openfass/analysis/cong-er-jin-zhi-wen-jian-zhi-zuo-function.md).

# 从二进制文件制作function

参考\[实验三]\(https\://github.com/openfaas/workshop/blob/master/lab3.md#custom-binaries-as-functions-optional-exercise)

选择Dockerfile作为模板

先看看这个Dockerfile，使用的经典的watchdog模板

```
FROM openfaas/classic-watchdog:0.18.0 as watchdog

FROM alpine:3.9
# 多阶段构建。存在多个 FROM 指令，每个 FROM 指令代表一个 stage 的开始部分。

RUN mkdir -p /home/app

# --from=watchdog，拷贝来自将第一阶段的fwatchdog
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
RUN chmod +x /usr/bin/fwatchdog

# Add non root user
RUN addgroup -S app && adduser app -S -G app
RUN chown app /home/app

WORKDIR /home/app

USER app

# Populate example here - i.e. "cat", "sha512sum" or "node index.js"
ENV fprocess="sort"
# Set to true to see request in function logs
ENV write_debug="false"

EXPOSE 8080

HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1

# 最后是通过fwatchdog启动的
CMD ["fwatchdog"]
```
