Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
Unable to connect with docker container

I have a server-api app.

In my localhost, I just need 2 commands to launch the app:

  1. npm install
  2. npm start

No more, and it works perfect at the port 3000.

I'm trying to dockerize my server to launch it with docker-compose.

Ok, this is my dockerfile:

FROM node:14-alpine AS development

ENV NODE_ENV development

WORKDIR /app

COPY package.json .
COPY package-lock.json .

RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "start"]

I launch the build command to build the image:

docker build --tag server-api . 

And when it finish, I run the container:

docker run -p 80:3000 server-api

The logs is perfect, it says that is running in the port 3000 and that I should connect to localhost:3000 to review my server-api app.

But, I undestand that is the port of the container, I had launch the container with the command -p 80:3000, so I check the port 80 of my computer... but nothing happens.

What should be my troubleshooting?

I already tried to get some info connecting with my container:

docker exec -it <container_id> sh 

But everythings looks perfect and is a simple app.

What Im doing wrong?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As @ErikMD says, all backend apps need to listen the special IP 0.0.0.0 to be dockerized (this problem doesnt happen with React).

I nedeed to read this post: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/

And to solve my problem I check how to change localhost to 0.0.0.0 as host.

By default my host was localhost.

So, I change this in my package.json:

"scripts": {
  "start": "json-server --watch db.json"
},

For this:

"scripts": {
   "start": "json-server --host 0.0.0.0 --port 8080 --watch db.json"
},

And now finally works perfect.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!