# Possible to run Serverless in a Docker container?

**URL:** <https://forum.serverless.com/t/possible-to-run-serverless-in-a-docker-container/5764>\
**Category:** Serverless Framework\
**Tags:** aws, lambda\
**Created:** [September 11, 2018, 8:46pm UTC](https://forum.serverless.com/t/possible-to-run-serverless-in-a-docker-container/5764 "2018-09-11T20:46:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dupkey](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/dupkey/32/2526_2.png) [@dupkey](https://forum.serverless.com/u/dupkey)\
**Post date:** [September 11, 2018, 8:46pm UTC](https://forum.serverless.com/t/possible-to-run-serverless-in-a-docker-container/5764/1 "2018-09-11T20:46:49Z")

</div>

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 &amp;&amp; \
    npm install -g serverless-offline &amp;&amp; \
    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!

---

<div class="post-metadata">

**Author:** ![teddy-gustiaux](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/teddy-gustiaux/32/2494_2.png) [@teddy-gustiaux](https://forum.serverless.com/u/teddy-gustiaux)\
**Post date:** [September 11, 2018, 9:50pm UTC](https://forum.serverless.com/t/possible-to-run-serverless-in-a-docker-container/5764/2 "2018-09-11T21:50:28Z")

</div>

According to the [serverless-offline documentation](https://github.com/dherault/serverless-offline), you should use `serverless offline start` or `sls offline start` to run it.

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

---

<div class="post-metadata">

**Author:** ![dupkey](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/dupkey/32/2526_2.png) [@dupkey](https://forum.serverless.com/u/dupkey)\
**Post date:** [September 11, 2018, 10:54pm UTC](https://forum.serverless.com/t/possible-to-run-serverless-in-a-docker-container/5764/3 "2018-09-11T22:54:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![teddy-gustiaux](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/teddy-gustiaux/32/2494_2.png) [@teddy-gustiaux](https://forum.serverless.com/u/teddy-gustiaux)\
**Post date:** [September 12, 2018, 4:00pm UTC](https://forum.serverless.com/t/possible-to-run-serverless-in-a-docker-container/5764/4 "2018-09-12T16:00:11Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![dupkey](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/dupkey/32/2526_2.png) [@dupkey](https://forum.serverless.com/u/dupkey)\
**Post date:** [September 13, 2018, 8:12pm UTC](https://forum.serverless.com/t/possible-to-run-serverless-in-a-docker-container/5764/5 "2018-09-13T20:12:42Z")

</div>

Thanks so much! That worked perfectly.

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

[https://gitlab.com/dupkey/serverless-examples/tree/master/docker-serverless-development-environment](https://gitlab.com/dupkey/serverless-examples/tree/master/docker-serverless-development-environment)

---

<div class="post-metadata">

**Author:** ![connorads](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/connorads/32/4468_2.png) [@connorads](https://forum.serverless.com/u/connorads)\
**Post date:** [August 6, 2020, 10:31pm UTC](https://forum.serverless.com/t/possible-to-run-serverless-in-a-docker-container/5764/6 "2020-08-06T22:31:10Z")

</div>

Thanks @dupkey and @teddy-gustiaux this was useful.

In case anyone wants to set the `host` in the `Dockerfile` only you can do it like this

```auto
CMD ["sls", "offline", "--host", "0.0.0.0"]

```

---

<div class="post-metadata">

**Author:** ![slinkardbrandon](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/slinkardbrandon/32/5072_2.png) [@slinkardbrandon](https://forum.serverless.com/u/slinkardbrandon)\
**Post date:** [January 15, 2021, 1:20pm UTC](https://forum.serverless.com/t/possible-to-run-serverless-in-a-docker-container/5764/7 "2021-01-15T13:20:00Z")

</div>

I had some issues with my base image not being able to find the `sls` or `serverless` commands automatically and I ended up having to actually provide a path to the serverless bin file, I also [created a Github Gist](https://gist.github.com/slinkardbrandon/200ad96d5705eb0cb138aee6b534285e) to hopefully give a little more help with this in the future to anyone needing a little bit more clarification.

Thanks to everyone on this thread for pointing me in the right direction with the host flag 🙂
