0

I'm running a nodejs app in a pod (together with a mongo container) Nodejs app listens on port 3000, which I expose from the container. I have published port 3000 on the pod. The container starts successfully (logs verified), but I can't reach my application on the host. When I curl to my app from within the pod it works. Containers run rootfull, OS: CentOS Linux release 8.0.1905 (Core). What am I missing?

curl http://localhost:3000
curl: (7) Failed to connect to localhost port 3000: No route to host
podman ps
CONTAINER ID  IMAGE                                                     COMMAND               CREATED         STATUS             PORTS                   NAMES
30da37306acf  registry.gitlab.com/xxx/switchboard:master  node main.js          34 minutes ago  Up 34 minutes ago  0.0.0.0:3000->3000/tcp  switchboard-app
acc08c71147b  docker.io/library/mongo:latest                            mongod                35 minutes ago  Up 35 minutes ago  0.0.0.0:3000->3000/tcp  switchboard-mongo
podman port switchboard-app
3000/tcp -> 0.0.0.0:3000
app.listen(3000, "0.0.0.0",function () {
  console.log('App is listening on port 3000!');
});
FROM node:13
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY /dist/apps/switchboard .
EXPOSE 3000
CMD [ "node", "main.js" ]
Jonas
  • 121,568
  • 97
  • 310
  • 388
Unibit
  • 89
  • 1
  • 5

1 Answers1

0

If you want to create production docker build, you can go another way. It's not a good idea to do npm install inside container, because it will be too large. Run npm run build first, and then copy builded statics into docker container, created with nginx image. So your Dockerfile shoud look like:

FROM nginx:1.13.0-alpine
COPY build/*  /usr/share/nginx/html/

also specify exposed ports correctly with docker run. So, if you want expose 3000, your steps is:

cd /project/dir
docker build -t switchboard-app .
docker run -d -p 3000:80 --name switchboard-app switchboard-app