3

I'm trying to create azure queue listener in docker and deploy it as an azure function.

Azure runs my docker with command similar to following:

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

The only thing that I need to do is to get that port variable and put it to func start --port $PORT field in entrypoint script, but the problem is that the bash doesn't see variables put through -e key.

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"]

Entrypoint:

#!/bin/bash

func start --port $PORT
12
  • What is your Dockerfile like, are you running func start .... in the container?
    – ahmelsayed
    Commented Apr 3, 2019 at 21:39
  • @ahmelsayed, I added the dockerfile code to my question. What about running the app, yes, I run it inside docker in entrypoint script
    – alectogeek
    Commented Apr 4, 2019 at 7:16
  • As I know, not all the docker image are supported for function. You can see Supported base images for Azure Functions from the Create a function on Linux using a custom image.
    – Charles Xu
    Commented Apr 4, 2019 at 7:36
  • @CharlesXu but I used exactly supported image from Microsoft official docker hub, didn't I?
    – alectogeek
    Commented Apr 4, 2019 at 8:20
  • Where is this container running? In AppService or AKS? Either way, everything looks good. It should work. Commented Apr 5, 2019 at 9:05

1 Answer 1

2

func is more for local development.

The mcr.microsoft.com/azure-functions/node:2.0 image already has the runtime packaged with the default entrypoint set to start it. You really don't need func here.

But, if ever required, even with just the runtime, you can customize the port

  1. You would have to remove these last few lines from the container
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. And run your container like this
docker run -d -p 16506:8081 --name queue-listener_0 -e ASPNETCORE_URLS=http://+:8081 ... 

Note that local.settings.json won't be picked up by the runtime. Your App Settings would have to be set manually as environment variables.

2
  • I guess I cannot customize the command running application because azure launches the container by itself. But I will try out build docker without last rows
    – alectogeek
    Commented Apr 5, 2019 at 18:09
  • Yes. The command is mostly useful if you are trying to run it on a custom docker host or AKS instead. Commented Apr 8, 2019 at 4:57

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.