Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

200
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda