1

I have the following simple server in express, with the following docker file

axiostest.mjs

import axios from "axios"
import express from "express"


const app = express();

app.get("/", (request, response) => {
    axios.get(`http://localhost:8888/admin_issues`).then(res => {
        console.log(res.data);
        response.send(res.data)
    }).catch(err => {
        console.log("ERRRROR")
        console.log(err);
        response.send(err)
    })
});

app.listen(1112, () => {
    console.log("Listen on the port 1112...");
});

DockerFile

FROM node:16

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY . .

EXPOSE 1112
CMD [ "node", "axiostest.mjs" ]

If I run the server normally with node axiostest.mjs, and then I do a postman call to localhost:1112

It works just fine

But If I build the docker container

docker build . -t me/express-test

and then i run it

docker run -p 49160:1112 -d me/express-test

If i do a postman call to localhost:49160

It says

"message": "connect ECONNREFUSED 127.0.0.1:8888"

Because axios is failing to connect to 127.0.0.1:8888

How can I fix this?

mouchin777
  • 1,428
  • 1
  • 31
  • 59

0 Answers0