如何从docker -e变量设置azure功能应用程序端口?

时间:2019-04-03 20:12:49

标签: node.js azure docker azure-functions

我正在尝试在docker中创建Azure队列侦听器并将其部署为Azure函数。

Azure使用类似于以下命令运行我的docker:

docker run -d -p 16506:8081 --name queue-listener_0 -e PORT=8081 ... 

我唯一需要做的就是获取该端口变量并将其放入入口点脚本的func start --port $PORT字段中,但是问题是bash看不到通过-e键放入的变量。 / p>

Dockerfile:

FROM tarampampam/node:10.10-alpine as buildContainer


COPY package.json package-lock.json entrypoint.sh host.json extensions.csproj proxies.json /app/
COPY /QueueTrigger/function.json /app/
#COPY /app/dist /app/dist

### only for local launch
#COPY  /local.settings.json /app


WORKDIR /app

RUN npm install
COPY . /app
RUN npm run build

FROM mcr.microsoft.com/azure-functions/node:2.0
WORKDIR /app
ENV AzureWebJobsScriptRoot=/app
ENV AzureWebJobs_ExtensionsPath=/app/bin

# Copy dependency definitions
COPY --from=buildContainer /app/package.json /app/

# Get all the code needed to run the app
COPY --from=buildContainer /app/dist /app/
COPY --from=buildContainer /app/function.json /app/QueueTrigger/
COPY --from=buildContainer /app/bin /app/bin
COPY --from=buildContainer /app/entrypoint.sh /app
COPY --from=buildContainer /app/host.json /app
COPY --from=buildContainer /app/extensions.csproj /app
COPY --from=buildContainer /app/proxies.json /app
COPY --from=buildContainer /app/resources /app/resources

### only for local launch
#COPY --from=buildContainer /app/local.settings.json /app


RUN chmod 755 /app/entrypoint.sh
COPY --from=buildContainer /app/node_modules /app/node_modules
RUN npm i -g azure-functions-core-tools@core --unsafe-perm true
RUN apt-get update && apt-get install -y ghostscript && gs -v

# Serve the app
ENTRYPOINT ["sh", "entrypoint.sh"]

入口点:

#!/bin/bash

func start --port $PORT

1 个答案:

答案 0 :(得分:1)

func更适合本地开发。

mcr.microsoft.com/azure-functions/node:2.0映像已经打包了运行时,并设置了用于启动它的默认入口点。您真的不需要func

但是,如果需要,即使仅使用运行时,也可以自定义端口

  1. 您将不得不从容器中删除最后几行
RUN chmod 755 /app/entrypoint.sh
RUN npm i -g azure-functions-core-tools@core --unsafe-perm true

# Serve the app
ENTRYPOINT ["sh", "entrypoint.sh"]
  1. 然后像这样运行您的容器
docker run -d -p 16506:8081 --name queue-listener_0 -e ASPNETCORE_URLS=http://+:8081 ... 
  

请注意,local.settings.json不会被运行时接收。您的应用程序设置必须手动设置为环境变量。