Possible to run Serverless in a Docker container?

aws
lambda

#1

I’m trying to containerize so that I don’t have to mess around with different versions of Node (among other thing) for different projects. The title says it all, is it possible to run Serverless in a Docker container?

I created a Dockerfile:

FROM node:8-alpine

RUN apk update

RUN npm install -g serverless && \
    npm install -g serverless-offline && \
    npm install -g yarn

WORKDIR /usr/src/app

COPY package*.json ./

RUN yarn

COPY . .

EXPOSE 3000

CMD [ "sls", "offline" ]

Build it: docker build -t serverless/docker .
Run it: docker run -p 49160:3000 serverless/docker

Response: curl: (56) Recv failure: Connection reset by peer

Any help or links are greatly appreciated!


#2

According to the serverless-offline documentation, you should use serverless offline start or sls offline start to run it.

Maybe using CMD [ "sls", "offline", "start" ] would help?


#3

I probably should have elaborated a bit more. It runs fine inside the container and lists the routes etc.

Serverless: Starting Offline: local/us-east-1.

Serverless: Routes for test:
Serverless: GET /{name}

Serverless: Offline listening on http://localhost:3000

However trying to access it from my host machine at 0.0.0.0:49160 yields the ‘Connection reset by peer’ error.


#4

In that case, maybe trying to change the host serverless-offline is listening on to 0.0.0.0 would help. You can do so by adding the snippet below to your serverless.yml.

custom:
  serverless-offline:
    host: 0.0.0.0

#5

Thanks so much! That worked perfectly.

I’ve included a link to the example in case anybody else is curious.