Docker Community Forums

Share and learn in the Docker community.

Hapijs application not responses correctly. HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers

My server

import Hapi from 'hapi';
import { load } from 'dotenv';
import mongoose from 'mongoose';
import plugins from './plugins';
import urls from './urls';


// Create a server with a host and port
const server = Hapi.server({
  host: '',
  port: process.env.PORT,
  routes: { cors: { origin: ['*'] } },

  { useNewUrlParser: true }

mongoose.connection.once('open', () => {
  console.log('connected to database');

// Start the server
async function start() {
  try {
    await server.register(plugins);

    await server.start();
  } catch (err) {

  console.log('Server running at:',;


My package.json

  "name": "civilizations",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "build": "babel src --out-dir dist --ignore spec.js",
    "dev": "NODE_ENV=dev nodemon ./src/server.js --exec babel-node",
    "debug": "NODE_ENV=test ndb ./src/server.js --exec babel-node",
    "flow": "flow",
    "lint": "eslint src/**",
    "pretty": "prettier --single-quote --trailing-comma es5 --write \"./src/**/*.js\"",
    "start": "node ./dist/server.js",
    "test": "jest --coverage",
    "test:watch": "jest --watch --coverage"

My Dockerfile

FROM node:10-slim
ENV HOME=/home/app
COPY package.json package-lock.json $HOME/lib/
COPY . $HOME/lib
RUN npm install --silent --progress=false && npm run build && npm cache clean --force
CMD ["npm", "start"]

Docker build.

$ docker build -t civilizations .
Sending build context to Docker daemon  1.287MB
Step 1/8 : FROM node:10-slim
 ---> 441869a4d9e2
Step 2/8 : ENV HOME=/home/app
 ---> Running in 521fee7ec29d
Removing intermediate container 521fee7ec29d
 ---> 6323749477fc
Step 3/8 : COPY package.json package-lock.json $HOME/lib/
 ---> 099554094c78
Step 4/8 : WORKDIR $HOME/lib
 ---> Running in e746f8839a75
Removing intermediate container e746f8839a75
 ---> 821ae99dcf16
Step 5/8 : COPY . $HOME/lib
 ---> 01013dc516fd
Step 6/8 : RUN npm install --silent --progress=false && npm run build && npm cache clean --force
 ---> Running in 7073aaf05d74
husky > setting up git hooks
husky > done
Love nodemon? You can now support the project via the open collective:

added 1072 packages from 466 contributors and audited 52088 packages in 23.969s
found 0 vulnerabilities

> civilizations@1.0.0 build /home/app/lib
> babel src --out-dir dist --ignore spec.js

src/cities/models.js -> dist/cities/models.js
src/cities/schema.js -> dist/cities/schema.js
src/cities/urls.js -> dist/cities/urls.js
src/cities/views.js -> dist/cities/views.js
src/core/schemaError.js -> dist/core/schemaError.js
src/plugins.js -> dist/plugins.js
src/professions/models.js -> dist/professions/models.js
src/professions/schema.js -> dist/professions/schema.js
src/professions/urls.js -> dist/professions/urls.js
src/professions/views.js -> dist/professions/views.js
src/server.js -> dist/server.js
src/server.test.js -> dist/server.test.js
src/spots/models.js -> dist/spots/models.js
src/spots/schema.js -> dist/spots/schema.js
src/spots/urls.js -> dist/spots/urls.js
src/spots/views.js -> dist/spots/views.js
src/urls.js -> dist/urls.js
npm WARN using --force I sure hope you know what you are doing.
Removing intermediate container 7073aaf05d74
 ---> c4c8b9e185ee
Step 7/8 : EXPOSE 5000
 ---> Running in 0b58e382a5bc
Removing intermediate container 0b58e382a5bc
 ---> bc4a4de7a0d1
Step 8/8 : CMD ["npm", "start"]
 ---> Running in 5462a444e235
Removing intermediate container 5462a444e235
 ---> ad039184f02e
Successfully built ad039184f02e
Successfully tagged civilizations:latest

Docker run:

$ docker run -itd -e MONGO_URL='mongodb://zzz:zzzz@zzz.zzz.zzz:zzz/zzzz' -e PORT=5000 --name civilizations -p 5000:5000  civilizations

Docker logs

$ docker logs -f 0e5438489683c

> civilizations@1.0.0 start /home/app/lib
> node ./dist/server.js

mongodb://zzz:zzzz@zzz.zzz.zzz:zzz/zzzz 5000
Server running at:
connected to database

Tests inside container /bin/bash

$ docker exec -i -t 0e5438489683c /bin/bash
root@0e5438489683:~/lib# wget
converted '' (ANSI_X3.4-1968) -> '' (UTF-8)
--2018-09-09 23:52:54--
Connecting to connected.
HTTP request sent, awaiting response... 200 OK
Length: 60 [application/json]
Saving to: 'index.html'

index.html                                 100%[=======================================================================================>]      60  --.-KB/s   in 0s     

2018-09-09 23:52:54 (8.20 MB/s) - 'index.html' saved [60/60]

And my logs:

Server running at:
connected to database

180909/235254.013, (1536537174013:0e5438489683:20:jlvigq8v:10000) [response,api,professions,get all professions] get /api/professions/ {"limit":10,"offset":0} 200 (188ms)

Tests from my shell. External

$ wget
--2018-09-09 20:54:15--
Connecting to connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.

--2018-09-09 20:54:16--  (try: 2)
Connecting to connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.

Did you fix this? I have the same problem with a simple flask app.
The port is responding but can’t seem to return anything.
Must be something to do with port forwarding response???

nvm in case anyone else has this problem:
I was using flask, by default it binds to localhost & 5000, so you have to specify:“”)