Skip to content
Advertisement

How to fix “curl (56) Recv failure: Connection reset by peer” error when doing a port mapping from docker container to host machine?

I have a Angular Project running in a docker container at port 4200. I have done a port mapping from docker container’s 4200 port to my localhost 4200.

I am running this on Ubuntu 16.04. When doing netstat -nltp, I get output

tcp6 0 0 :::4200 :::* LISTEN

My Dockerfile looks like :

FROM node
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm cache clean --force
RUN npm install
COPY . /usr/src/app
EXPOSE 4200
CMD ["npm","start"]

I expected when running curl :::4200, to show me the webpage sourcecode instead of the error, curl (56) Recv failure: Connection reset by peer

Advertisement

Answer

Changing the following in package.json for my angular project did the trick.

BEFORE

{
  "name": "client",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  }

AFTER

{
  "name": "client",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --host 0.0.0.0",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

Follow this link for further details

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement