Unable to access docker container from the port mapped by docker

I have created a docker container but unable to run it on the port mapped by the docker (http://localhost:3000). Below are the details of docker configurations that I am using in my app.

Docker version : 17.05.0-ce

  • Docker compose permission denied on cento 7 when creating mysql database Linux issue
  • Custom Docker Swarm Scheduler
  • connecting Docker to a cloud provider, Amazon AWS
  • Unable to connect to mongoDB running in docker container
  • How to mount a device of host to host in a Docker container?
  • how to get the layers of a docker image on local host
  • Os : ubuntu 16.04

    My Dockerfile:

    FROM node:boron
    # Create app directory
    RUN mkdir -p /usr/src/app
    WORKDIR /usr/src/app
    
    COPY   . /usr/src/app
    
    RUN     npm install -g bower 
    RUN     npm install -g grunt-cli
    RUN     npm install 
    RUN     bower install --allow-root
    #RUN     grunt --force
    EXPOSE 3000
    CMD     ["grunt", "serve"]
    

    Creating docker container:

    docker build -t viki76/ng-app .
    

    Running Container:

    docker run  -p 3000:3000 -d viki76/ng-app
    

    docker ps:

    CONTAINER ID   IMAGE         COMMAND       CREATED    STATUS     PORTS  
    
    21541171d884   viki/ng-app   "grunt serve"  10 min ago Up    0.0.0.0:3000->3000/tcp
    

    EDIT:

    Updated Dockerfile configuration

    EXPOSE 9000
    

    $ docker run -p 9000:9000 viki76/ng-app

    Running "serve" task
    
    Running "clean:server" (clean) task
    >> 1 path cleaned.
    
    Running "wiredep:app" (wiredep) task
    
    Running "wiredep:test" (wiredep) task
    
    Running "concurrent:server" (concurrent) task
    
    Running "copy:styles" (copy) task
    Copied 2 files
    
    Done, without errors.
    
    
    Execution Time (2017-05-17 13:00:13 UTC-0)
    loading tasks               189ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 88%
    loading grunt-contrib-copy   11ms  ▇▇ 5%
    copy:styles                  16ms  ▇▇▇ 7%
    Total 216ms
    
    Running "postcss:server" (postcss) task
    >> 2 processed stylesheets created.
    
    Running "connect:livereload" (connect) task
    Started connect web server on http://localhost:9000
    
    Running "watch" task
    Waiting...
    

    From Gruntfile.js

    connect: {
      options: {
        port: 9000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname: '0.0.0.0',
        livereload: 35729
      },
    

    Please help me to fix it.
    Thanks

  • How can I create a docker image from the current system?
  • Linux based docker images on Windows Server 2016 TP5
  • Node.js docker container runs when folder is located on desktop but wont in C drive
  • Docker: transaction check error
  • docker pull inside docker in a private Hub didn't work
  • Using a docker container querying an AWS RDS Instance
  • 3 Solutions collect form web for “Unable to access docker container from the port mapped by docker”

    I think your problem is that grunt is binding to localhost:9000 – which is internal to the container so the port you’re publishing won’t have any effect.

    It needs to be listening on 0.0.0.0:9000 – I couldn’t tell you off hand what your Gruntfile.js should say for that to happen, but off-hand it looks like, out of the box, grunt serve will only serve from localhost.

    You’re doing everyhthing right, though I’m assuming that your problem is simply configuration.

    By default, grunt-serve serves on port 9000, not 3000. Do you want to try and EXPOSE and publish that port?

    Try running the container in Host mode:

    --net="host"
    

    Pass the above when you run the container.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.