Docker running host but not accessible

I have created sample docker image. When I try to run the image it is displaying running on http://8000 but it is not running actually in the localhost

How to resolve that issue?

docker file:

FROM node:carbon

# Create app directory
WORKDIR C:\Users\user2\FirstDocker

# 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 install --only=production

# Bundle app source
COPY . .

EXPOSE 8000
CMD [ "npm", "start" ]

server js:

'use strict';

const express = require('express');

// Constants
const PORT = 8000;


// App
const app = express();
app.get('/', (req, res) => {
  res.send('Hello user\n');
});

app.listen(PORT, HOST);
console.log(`Running on http://${PORT}`);

package.json

[{
  "name": "DockerApplication",
  "version": "1.0.0",
  "description": "Node.js on Docker",
  "author": "Nithya <nitikishu@gmail.com>",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "express": "^4.16.1"
  }
}]![Capture2|578x500](upload://gKomeK7xhRUjviTWetm4uIZjZ1u.PNG)

when u started the container using the image from the dockerfile, what does the docker run command look like?
did u map the containers port onto the host using the -p or -P parameter?

I used docker run nitikishu/sampledocker command
it showing running on http://8000

Even If I run by docker run -p 8001:8000 nitikishu/sampledocker
same thing is happening

I cant able to access the localhost:8000 and also mapped host localhost:8001

this is windows host, right?
WORKDIR C:\Users\user2\FirstDocker

on windows, docker is run on a hidden virtual machine…

you need to get its address… you can docker inspect container_id

almost always it is 192.168.99.100

yes @sdetweil. this is windows host only. docker inspect container-id gives some details. but in that 192.168.99.100 is not there.

should i check the host using 192.168.99.100:8000

show the output of docker inspect

user2@system2 MINGW64 ~/firstdocker
$ docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1f57effa333d nitikishu/sampledocker “npm start” 13 minutes ago Up 13 minutes 4000/tcp friendly_lovelace

user2@system2 MINGW64 ~/firstdocker
$ docker inspect 1f57effa333d
[
{
“Id”: “1f57effa333d5364cd6d23ba46b7f82b3283f8c4f1d70b7b0d02266024dd5a23”,
“Created”: “2018-01-09T12:34:11.313641627Z”,
“Path”: “npm”,
“Args”: [
“start”
],
“State”: {
“Status”: “running”,
“Running”: true,
“Paused”: false,
“Restarting”: false,
“OOMKilled”: false,
“Dead”: false,
“Pid”: 14094,
“ExitCode”: 0,
“Error”: “”,
“StartedAt”: “2018-01-09T12:34:11.927832818Z”,
“FinishedAt”: “0001-01-01T00:00:00Z”
},
“Image”: “sha256:c136a2eddc792c066188ac066f7984f9a5df5a2409912c5f2770eabdca2d65d9”,
“ResolvConfPath”: “/mnt/sda1/var/lib/docker/containers/1f57effa333d5364cd6d23ba46b7f82b3283f8c4f1d70b7b0d02266024dd5a23/resolv.conf”,
“HostnamePath”: “/mnt/sda1/var/lib/docker/containers/1f57effa333d5364cd6d23ba46b7f82b3283f8c4f1d70b7b0d02266024dd5a23/hostname”,
“HostsPath”: “/mnt/sda1/var/lib/docker/containers/1f57effa333d5364cd6d23ba46b7f82b3283f8c4f1d70b7b0d02266024dd5a23/hosts”,
“LogPath”: “/mnt/sda1/var/lib/docker/containers/1f57effa333d5364cd6d23ba46b7f82b3283f8c4f1d70b7b0d02266024dd5a23/1f57effa333d5364cd6d23ba46b7f82b3283f8c4f1d70b7b0d
02266024dd5a23-json.log”,
“Name”: “/friendly_lovelace”,
“RestartCount”: 0,
“Driver”: “aufs”,
“MountLabel”: “”,
“ProcessLabel”: “”,
“AppArmorProfile”: “”,
“ExecIDs”: null,
“HostConfig”: {
“Binds”: null,
“ContainerIDFile”: “”,
“LogConfig”: {
“Type”: “json-file”,
“Config”: {}
},
“NetworkMode”: “default”,
“PortBindings”: {},
“RestartPolicy”: {
“Name”: “no”,
“MaximumRetryCount”: 0
},
“AutoRemove”: false,
“VolumeDriver”: “”,
“VolumesFrom”: null,
“CapAdd”: null,
“CapDrop”: null,
“Dns”: [],
“DnsOptions”: [],
“DnsSearch”: [],
“ExtraHosts”: null,
“GroupAdd”: null,
“IpcMode”: “”,
“Cgroup”: “”,
“Links”: null,
“OomScoreAdj”: 0,
“PidMode”: “”,
“Privileged”: false,
“PublishAllPorts”: false,
“ReadonlyRootfs”: false,
“SecurityOpt”: null,
“UTSMode”: “”,
“UsernsMode”: “”,
“ShmSize”: 67108864,
“Runtime”: “runc”,
“ConsoleSize”: [
69,
171
],
“Isolation”: “”,
“CpuShares”: 0,
“Memory”: 0,
“NanoCpus”: 0,
“CgroupParent”: “”,
“BlkioWeight”: 0,
“BlkioWeightDevice”: null,
“BlkioDeviceReadBps”: null,
“BlkioDeviceWriteBps”: null,
“BlkioDeviceReadIOps”: null,
“BlkioDeviceWriteIOps”: null,
“CpuPeriod”: 0,
“CpuQuota”: 0,
“CpuRealtimePeriod”: 0,
“CpuRealtimeRuntime”: 0,
“CpusetCpus”: “”,
“CpusetMems”: “”,
“Devices”: [],
“DeviceCgroupRules”: null,
“DiskQuota”: 0,
“KernelMemory”: 0,
“MemoryReservation”: 0,
“MemorySwap”: 0,
“MemorySwappiness”: -1,
“OomKillDisable”: false,
“PidsLimit”: 0,
“Ulimits”: null,
“CpuCount”: 0,
“CpuPercent”: 0,
“IOMaximumIOps”: 0,
“IOMaximumBandwidth”: 0
},
“GraphDriver”: {
“Data”: null,
“Name”: “aufs”
},
“Mounts”: [],
“Config”: {
“Hostname”: “1f57effa333d”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: false,
“AttachStdout”: true,
“AttachStderr”: true,
“ExposedPorts”: {
“4000/tcp”: {}
},
“Tty”: false,
“OpenStdin”: false,
“StdinOnce”: false,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”,
“NODE_VERSION=8.9.4”,
“YARN_VERSION=1.3.2”
],
“Cmd”: [
“npm”,
“start”
],
“ArgsEscaped”: true,
“Image”: “nitikishu/sampledocker”,
“Volumes”: null,
“WorkingDir”: “/C:Usersuser2FirstDocker”,
“Entrypoint”: null,
“OnBuild”: null,
“Labels”: {}
},
“NetworkSettings”: {
“Bridge”: “”,
“SandboxID”: “8918f5493a6ea1c2fbbf04ceffb0b410b54ea41c5502a44d8634894fb107dca6”,
“HairpinMode”: false,
“LinkLocalIPv6Address”: “”,
“LinkLocalIPv6PrefixLen”: 0,
“Ports”: {
“4000/tcp”: null
},
“SandboxKey”: “/var/run/docker/netns/8918f5493a6e”,
“SecondaryIPAddresses”: null,
“SecondaryIPv6Addresses”: null,
“EndpointID”: “457d1f89d73738501cc60cdfae6ac4c25cd032def542c59f51111f45bb4ac68c”,
“Gateway”: “172.17.0.1”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“IPAddress”: “172.17.0.12”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“MacAddress”: “02:42:ac:11:00:0c”,
“Networks”: {
“bridge”: {
“IPAMConfig”: null,
“Links”: null,
“Aliases”: null,
“NetworkID”: “8649f71393999be7058a5e0df86cddbe8651708eaca3e4564454ee7f952d2017”,
“EndpointID”: “457d1f89d73738501cc60cdfae6ac4c25cd032def542c59f51111f45bb4ac68c”,
“Gateway”: “172.17.0.1”,
“IPAddress”: “172.17.0.12”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“MacAddress”: “02:42:ac:11:00:0c”,
“DriverOpts”: null
}
}
}
}
]

this my docker inspect command details

hmm…

appears the dockefile you listed wasn’'t used to create this container, as the dockerfile exposes port 8000, but the inspect shows 4000

also, you did not map the port onto the host at all with -p

the container address is

and the port exposed is 4000, but not mapped to the host…

but, http://172.17.0.12:4000 should work

Initially I used 8000 port now I changed and using 4000 so that I used that to inspect. unfortunately I shared previous code(8000 port).

okay I will check and update the output

docker run -P 172.17.0.2:4000 nitikishu/sampledocker it is showing like

unable to find image 172.17.0.2:4000 locally

Error response from daemon:repository 172.17.0.2 not found:does not exist or no pull access

@sdetweil Now, Inspect the container for that image it is displaying ipaddress as 172.17.0.2 only. So, I used that ip address to map

When I start the docker quick terminal

docker is configured to use the default machine with ip 192.168.99.100 for help getting started,check out docs at https://docs.docker.com

So, If I run my container or image, why it would not work on this port
192.168.99.100

docker commands:

docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com

Start interactive shell

user2@system2 MINGW64 ~
$ cd firstdocker

user2@system2 MINGW64 ~/firstdocker
$ docker pull nitikishu/sampledocker
Using default tag: latest
latest: Pulling from nitikishu/sampledocker
Digest: sha256:1b1cb55b4962036cd07e61fd1a05ceeeebb2ccd9314aa26a3231d2d9e6198875
Status: Image is up to date for nitikishu/sampledocker:latest

user2@system2 MINGW64 ~/firstdocker
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
47d789148558 c136a2eddc79 “npm start” 19 minutes ago Up 19 minutes 4000/tcp competent_banach

user2@system2 MINGW64 ~/firstdocker
$ docker run nitikishu/sampledocker

DockerApplication@1.0.0 start /C:Usersuser2FirstDocker
node server.js

Running on http://4000

user2@system2 MINGW64 ~/firstdocker
$ docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fb25b170ab9a nitikishu/sampledocker “npm start” 54 seconds ago Up 50 seconds 4000/tcp jovial_ritchie

user2@system2 MINGW64 ~/firstdocker
$ docker inspect nitikishu/sampledocker
[
{
“Id”: “sha256:48f2752fb80b7ce4e706df0f57ccf681d22f465432db26a09dd097263b926707”,
“RepoTags”: [
“nitikishu/sampledocker:latest”
],
“RepoDigests”: [
“nitikishu/sampledocker@sha256:1b1cb55b4962036cd07e61fd1a05ceeeebb2ccd9314aa26a3231d2d9e6198875”
],
“Parent”: “sha256:402e338dc1d3b72d023dfa8ba26a3650570c1bca5d51ba264c5dc0f1b410e05c”,
“Comment”: “”,
“Created”: “2018-01-10T05:16:35.49919358Z”,
“Container”: “9a1e12d8cd75315dd80f9eecc00d49431ada9601a09c446ec2d76748a2f83a0a”,
“ContainerConfig”: {
“Hostname”: “9a1e12d8cd75”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: false,
“AttachStdout”: false,
“AttachStderr”: false,
“ExposedPorts”: {
“4000/tcp”: {}
},
“Tty”: false,
“OpenStdin”: false,
“StdinOnce”: false,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”,
“NODE_VERSION=8.9.4”,
“YARN_VERSION=1.3.2”
],
“Cmd”: [
“/bin/sh”,
“-c”,
"#(nop) ",
“CMD ["npm" "start"]”
],
“ArgsEscaped”: true,
“Image”: “sha256:402e338dc1d3b72d023dfa8ba26a3650570c1bca5d51ba264c5dc0f1b410e05c”,
“Volumes”: null,
“WorkingDir”: “/C:Usersuser2FirstDocker”,
“Entrypoint”: null,
“OnBuild”: ,
“Labels”: {}
},
“DockerVersion”: “17.06.0-ce”,
“Author”: “”,
“Config”: {
“Hostname”: “”,
“Domainname”: “”,
“User”: “”,
“AttachStdin”: false,
“AttachStdout”: false,
“AttachStderr”: false,
“ExposedPorts”: {
“4000/tcp”: {}
},
“Tty”: false,
“OpenStdin”: false,
“StdinOnce”: false,
“Env”: [
“PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”,
“NODE_VERSION=8.9.4”,
“YARN_VERSION=1.3.2”
],
“Cmd”: [
“npm”,
“start”
],
“ArgsEscaped”: true,
“Image”: “sha256:402e338dc1d3b72d023dfa8ba26a3650570c1bca5d51ba264c5dc0f1b410e05c”,
“Volumes”: null,
“WorkingDir”: “/C:Usersuser2FirstDocker”,
“Entrypoint”: null,
“OnBuild”: ,
“Labels”: null
},
“Architecture”: “amd64”,
“Os”: “linux”,
“Size”: 679308522,
“VirtualSize”: 679308522,
“GraphDriver”: {
“Data”: null,
“Name”: “aufs”
},
“RootFS”: {
“Type”: “layers”,
“Layers”: [
“sha256:4bcdffd70da292293d059d2435c7056711fab2655f8b74f48ad0abe042b63687”,
“sha256:b9914afd042f489b84cfafa104175dd764d2ceeeef523e99b43044d8b224fdd0”,
“sha256:06b8d020c11b32eac35be52aab5197fe4c679f37dbb9bcd5a4342cee00a92199”,
“sha256:8fe6d5dcea4516a681465ce7eddd485ac2800fe4408d19ab447cfed1095f0149”,
“sha256:d4141af68ac4c5ac9d49ad35dc3ddcd0b2bd3c1af0729dde8e3413cb30fc76e4”,
“sha256:50599c766115e3c8e0c82f2344debe529f6995e990e33529254dbb013760cb56”,
“sha256:299e6ab856bed7e146f520cf9ad888e878d96f19b4335314d82b8b5c06069680”,
“sha256:092504c250f7f14bb7bd3478ce3ef7afb1d8e409a929ca30e6ac502a364adc52”,
“sha256:b478d6e8e643df3b95340ff0f7086b456624c543ac24ecc981d2e8b856f23939”,
“sha256:9d3a32ec7fbb74b372b40c6c5e21ad308ec87776e3bf9395c39df0e6b3e5927a”,
“sha256:fe0d079bb86bdb8464bffed1dd380476e446078f53cdb0cbb19332745c3f995a”,
“sha256:a92d02371a6be203f15d7413db50125af81d27ab5a4fc415ec310931142b2cf4”
]
}
}
]

user2@system2 MINGW64 ~/firstdocker
$

ok, docker on windows… that is different because of the virtual machine

http://192.168.99.100:4000 

should work to access the container port directly.

otherwise, to map a container port, you would use the -p host_port:container_port parms on docker run

container port is 4000. host-port is 192.168.99.100 right?

to map the container port

docker run -p 192.168.99.100:4000

is that right way?
after build the container should I run the host 192.168.99.100:4000 will work?

no…

the parm is xxxx:yyyy

the left side of the -p (xxxx) is the host port
the right side (yyyy) is the container port

so to map the containers 4000 onto 8181 for example it would be

docker run -d -p 8181:4000 ..... rest of parms

if you do NOT map the port onto the host, then you would use the url

http://192.168.99.100:4000

to access the container port directly from the host

yeah ok. I tried. sample page is working. But I tried another node application… In that I am getting some error while login in to the system.

user2@system2 MINGW64 ~/pms
$ docker run nitikishu/pmsdocker

pmsproject@1.0.0 start /C:Usersuser2PMS
node server.js

{ Error: Cannot find module '../build/Release/bson'
    at Function.Module._resolveFilename (module.js:538:15)
    at Function.Module._load (module.js:468:25)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/C:Usersuser2PMS/node_modules/mongoose/node_modules/bson/ext/index.js:15:10)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3) code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
 server running on port 8088
  Press CTRL-C to stop

How do I resolve this one?

This application is normally running on my host correctly but when , I am trying to run it on docker I am getting the above error. So that unable to login to the application.

and also I not having any file in that path

at Object. (/C:Usersuser2PMS/node_modules/mongoose/node_modules/bson/ext/index.js:15:10)

In this path I am not having node-modules/bson/ext/index file under the mongoose folder

i do not know after that