I locally launched docker image successfully but i can't send any request on localhost.I have errors socket hang up in postman and localhost didn't send any data.
docker file
FROM node:20-alpine
MAINTAINER Some Dev
RUN mkdir /app
WORKDIR /app
COPY ./backend /app
RUN npm i
CMD ["npm","start"]
app.ts and small rout that I'm trying to reach configs.PORT = 5000 configs.HOST = 0.0.0.0
app.get('/hello',async (req:Request,res:Response,next:NextFunction)=>{
res.json("Hello")
})
const startServer = async () => {
try {
await mongoose.connect(configs.DB_URL);
console.log("Connected to MongoDB");
app.listen(+configs.PORT, configs.HOST,() =>{
console.log(`Server listening on ${configs.PORT} and host ${configs.HOST}`);
})
} catch (err) {
throw new ApiError(err.message, err.status);
}
};
startServer();
docker build -t buxonlineappv2 .
docker run -d -p 5555:80 buxonlineappv2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6fd90778e2df buxonlineappv2 "docker-entrypoint.s…" 51 seconds ago Up 39 seconds 0.0.0.0:5555->80/tcp jolly_saha
In first i added host 0.0.0.0. Tried different ports. Tried localhost:5555/hello 0.0.0.0:5555/hello http:localhost:5555/hello
since your server is listening on port 5000, you should run this command to run the container:
docker run -d -p 5555:5000 buxonlineappv2
so that 5555 port on host maps with 5000 port in container.