Docker Community Forums

Share and learn in the Docker community.

Docker machine port exposed problem (Windows host) [SOLVED]

Hi everyone,

I have a container with port 8080 exposed and I use docker-compose to build and run this container.
But when I try to access on localhost:8080 on my web browser I can’t access to the service listening on this port.

This my configurations :

docker-compose :

version: '2'
services:
  financial-tracker:
    build: .
    environment:
      - APP_TOKEN=${APP_TOKEN}
      - NODE_ENV=PROD
    ports:
      - "8080:8080"

Dockerfile :

FROM node:16.13.0-alpine

WORKDIR /usr/src/app

COPY package.json .
RUN npm install

COPY ./config ./config
COPY ./dist ./dist

EXPOSE 8080

CMD ["npm", "start"]

My application work perfectly outside any docker container, I can access to this on 8080 port.

I’ve also trying to find IP adress of container and access like this on web browser : 172.18.0.2:8080. But it doesn’t work…

I’ve used docker ps to see if my container has listening on port 8080 and it does.

6c684868b07a   financialtracker_financial-tracker   "docker-entrypoint.s…"   6 seconds ago   Up 4 seconds    0.0.0.0:8080->8080/tcp   financialtracker_financial-tracker_1

(Sorry for my approximative english…)

Thanks for the help. :slight_smile:

What web server are you using for your application? And how did you configure that?

It’s probably only accepting connections for localhost, but: in a Docker container localhost in the container is not the same as localhost on the host that is running the container. Most often you’ll need your web server to listen on 0:0:0:0 to allow for external connections, rather than to listen to, say, 127.0.0.1.

Thanks for reply.

I use Fastify framework, it manage his own server.
I check the documentation and you’re right, for security reason the binding adress is only ‘127.0.0.1’ : Fastify listen binding docs. It seems works now.

Thanks for your help !

1 Like