Docker Community Forums

Share and learn in the Docker community.

Unable to access localhost 3000 for node js app

(Leexha) #1

Dear all,

I have a node js app as below

const express = require('express')
const app = express()

app.get('/', (req, res) => res.send('Hello there man!'))

app.listen(3000, () => console.log('Example app listening on port 3000!'))

So i have a docker file which is as below

FROM node:latest

# Create app directoryy
RUN mkdir -p /usr/src/app/
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 /usr/src/app/

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

# Bundle app source
COPY . .

CMD [ "node", "sampleApp.js" ]
C:\Users\adrlee\Desktop\oracle\wercker\nodeJS_wercker_k8 - Copy>docker run 669bf025e027 -p 3000:3000
Example app listening on port 3000!

I tried to access the localhost but nothing. What is going on? 2 weeks agot i was able to do so. whats the difference now?

(Martin Terp) #2


if you put “-p 3000:3000” AFTER the imageId/name, it will think its arguments to the CMD defined in the Dockerfile.

So you need to put it after docker run, like:

docker run -p 3000:3000 669bf025e027