Running app contained in Docker container in system browser2019 Community Moderator ElectionHow is Docker different from a virtual machine?Should I use Vagrant or Docker for creating an isolated environment?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersRun a Docker Image as a ContainerCopying files from Docker container to hostCopying files from host to Docker containerFrom inside of a Docker container, how do I connect to the localhost of the machine?difficulties exposing my express docker container to the world

Isn't the word "experience" wrongly used in this context?

Hackerrank All Women's Codesprint 2019: Name the Product

Why does Surtur say that Thor is Asgard's doom?

When did hardware antialiasing start being available?

DisplayForm problem with pi in FractionBox

Turning a hard to access nut?

How can an organ that provides biological immortality be unable to regenerate?

Friend wants my recommendation but I don't want to

Do native speakers use "ultima" and "proxima" frequently in spoken English?

What is the tangent at a sharp point on a curve?

Why didn’t Eve recognize the little cockroach as a living organism?

Norwegian Refugee travel document

Recursively updating the MLE as new observations stream in

Single word to change groups

Writing in a Christian voice

UK Tourist Visa- Enquiry

Emojional cryptic crossword

How do researchers send unsolicited emails asking for feedback on their works?

Is VPN a layer 3 concept?

Can other pieces capture a threatening piece and prevent a checkmate?

Pre-Employment Background Check With Consent For Future Checks

Knife as defense against stray dogs

Which partition to make active?

"Marked down as someone wanting to sell shares." What does that mean?



Running app contained in Docker container in system browser



2019 Community Moderator ElectionHow is Docker different from a virtual machine?Should I use Vagrant or Docker for creating an isolated environment?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersRun a Docker Image as a ContainerCopying files from Docker container to hostCopying files from host to Docker containerFrom inside of a Docker container, how do I connect to the localhost of the machine?difficulties exposing my express docker container to the world










1















I have the following files:



Dockerfile:



FROM node:8

# Create app directory
WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

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


server.js:



'use strict';

const express = require('express');

// Constants
const PORT = 8080;
const HOST = '0.0.0.0';

// App
const app = express();
app.get('/', (req, res) =>
res.send('Hello worldn');
);

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


package.json:




"name": "docker_web_app",
"version": "1.0.0",
"description": "Node.js on Docker",
"author": "First Last <first.last@example.com>",
"main": "server.js",
"scripts":
"start": "node server.js"
,
"dependencies":
"express": "^4.16.1"




.dockerignore:



node_modules
npm-debug.log


Then I build Docker images:



docker build -t nodeapp -f ./Dockerfile .



It works, the image is created. Then I run it:



docker run -p 49160:8080 -d nodeapp



And exec following:



docker exec -it <container id> /bin/bash



If I type curl -i localhost:49160, I get Failed to connect to localhost port 49160: Connection refused.



Nonetheless, if I type curl -i localhost:8080 that's ok:



HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 12
ETag: W/"c-M6tWOb/Y57lesdjQuHeB1P/qTV0"
Date: Wed, 06 Mar 2019 23:20:41 GMT
Connection: keep-alive

Hello world


Yet, I can't get localhost:8080 (neither localhost:49160) in the Chrome on my original system, i.e., out of Docker at all.



Is it possible to run dockered apps in browsers? How to fix it to make it work?




EDIT:



1) I must have checked out an IP address with docker-machine ip

2) go to <docker-machine-ip>:49160










share|improve this question
























  • From what you describe, accessing the container on port 49160 from the host should be working. You are mapping port 8080 from inside the container, to port 49160 on the host. localhost:49160 should do it. Check the port number in the run command again?

    – Andreas Lorenzen
    Mar 6 at 23:44












  • You are following the guide here: nodejs.org/en/docs/guides/nodejs-docker-webapp - I just completed it, and I can see the "Hello world" page at localhost:49160 just fine. You need to double check everything I think. I can upload to a repo if you want to compare it?

    – Andreas Lorenzen
    Mar 7 at 0:03











  • I've done things again and still doesn't work. You can upload your one to a repo, it would be more than nice.

    – Damian Czapiewski
    Mar 7 at 0:06






  • 1





    Ok, uploaded here: github.com/aplorenzen/nodejs-docker-webapp

    – Andreas Lorenzen
    Mar 7 at 0:18






  • 1





    Aha, I am not using docker-machine at all. Just Docker for Windows

    – Andreas Lorenzen
    Mar 7 at 1:20















1















I have the following files:



Dockerfile:



FROM node:8

# Create app directory
WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

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


server.js:



'use strict';

const express = require('express');

// Constants
const PORT = 8080;
const HOST = '0.0.0.0';

// App
const app = express();
app.get('/', (req, res) =>
res.send('Hello worldn');
);

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


package.json:




"name": "docker_web_app",
"version": "1.0.0",
"description": "Node.js on Docker",
"author": "First Last <first.last@example.com>",
"main": "server.js",
"scripts":
"start": "node server.js"
,
"dependencies":
"express": "^4.16.1"




.dockerignore:



node_modules
npm-debug.log


Then I build Docker images:



docker build -t nodeapp -f ./Dockerfile .



It works, the image is created. Then I run it:



docker run -p 49160:8080 -d nodeapp



And exec following:



docker exec -it <container id> /bin/bash



If I type curl -i localhost:49160, I get Failed to connect to localhost port 49160: Connection refused.



Nonetheless, if I type curl -i localhost:8080 that's ok:



HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 12
ETag: W/"c-M6tWOb/Y57lesdjQuHeB1P/qTV0"
Date: Wed, 06 Mar 2019 23:20:41 GMT
Connection: keep-alive

Hello world


Yet, I can't get localhost:8080 (neither localhost:49160) in the Chrome on my original system, i.e., out of Docker at all.



Is it possible to run dockered apps in browsers? How to fix it to make it work?




EDIT:



1) I must have checked out an IP address with docker-machine ip

2) go to <docker-machine-ip>:49160










share|improve this question
























  • From what you describe, accessing the container on port 49160 from the host should be working. You are mapping port 8080 from inside the container, to port 49160 on the host. localhost:49160 should do it. Check the port number in the run command again?

    – Andreas Lorenzen
    Mar 6 at 23:44












  • You are following the guide here: nodejs.org/en/docs/guides/nodejs-docker-webapp - I just completed it, and I can see the "Hello world" page at localhost:49160 just fine. You need to double check everything I think. I can upload to a repo if you want to compare it?

    – Andreas Lorenzen
    Mar 7 at 0:03











  • I've done things again and still doesn't work. You can upload your one to a repo, it would be more than nice.

    – Damian Czapiewski
    Mar 7 at 0:06






  • 1





    Ok, uploaded here: github.com/aplorenzen/nodejs-docker-webapp

    – Andreas Lorenzen
    Mar 7 at 0:18






  • 1





    Aha, I am not using docker-machine at all. Just Docker for Windows

    – Andreas Lorenzen
    Mar 7 at 1:20













1












1








1








I have the following files:



Dockerfile:



FROM node:8

# Create app directory
WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

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


server.js:



'use strict';

const express = require('express');

// Constants
const PORT = 8080;
const HOST = '0.0.0.0';

// App
const app = express();
app.get('/', (req, res) =>
res.send('Hello worldn');
);

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


package.json:




"name": "docker_web_app",
"version": "1.0.0",
"description": "Node.js on Docker",
"author": "First Last <first.last@example.com>",
"main": "server.js",
"scripts":
"start": "node server.js"
,
"dependencies":
"express": "^4.16.1"




.dockerignore:



node_modules
npm-debug.log


Then I build Docker images:



docker build -t nodeapp -f ./Dockerfile .



It works, the image is created. Then I run it:



docker run -p 49160:8080 -d nodeapp



And exec following:



docker exec -it <container id> /bin/bash



If I type curl -i localhost:49160, I get Failed to connect to localhost port 49160: Connection refused.



Nonetheless, if I type curl -i localhost:8080 that's ok:



HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 12
ETag: W/"c-M6tWOb/Y57lesdjQuHeB1P/qTV0"
Date: Wed, 06 Mar 2019 23:20:41 GMT
Connection: keep-alive

Hello world


Yet, I can't get localhost:8080 (neither localhost:49160) in the Chrome on my original system, i.e., out of Docker at all.



Is it possible to run dockered apps in browsers? How to fix it to make it work?




EDIT:



1) I must have checked out an IP address with docker-machine ip

2) go to <docker-machine-ip>:49160










share|improve this question
















I have the following files:



Dockerfile:



FROM node:8

# Create app directory
WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

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


server.js:



'use strict';

const express = require('express');

// Constants
const PORT = 8080;
const HOST = '0.0.0.0';

// App
const app = express();
app.get('/', (req, res) =>
res.send('Hello worldn');
);

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


package.json:




"name": "docker_web_app",
"version": "1.0.0",
"description": "Node.js on Docker",
"author": "First Last <first.last@example.com>",
"main": "server.js",
"scripts":
"start": "node server.js"
,
"dependencies":
"express": "^4.16.1"




.dockerignore:



node_modules
npm-debug.log


Then I build Docker images:



docker build -t nodeapp -f ./Dockerfile .



It works, the image is created. Then I run it:



docker run -p 49160:8080 -d nodeapp



And exec following:



docker exec -it <container id> /bin/bash



If I type curl -i localhost:49160, I get Failed to connect to localhost port 49160: Connection refused.



Nonetheless, if I type curl -i localhost:8080 that's ok:



HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 12
ETag: W/"c-M6tWOb/Y57lesdjQuHeB1P/qTV0"
Date: Wed, 06 Mar 2019 23:20:41 GMT
Connection: keep-alive

Hello world


Yet, I can't get localhost:8080 (neither localhost:49160) in the Chrome on my original system, i.e., out of Docker at all.



Is it possible to run dockered apps in browsers? How to fix it to make it work?




EDIT:



1) I must have checked out an IP address with docker-machine ip

2) go to <docker-machine-ip>:49160







docker






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 1:17







Damian Czapiewski

















asked Mar 6 at 23:32









Damian CzapiewskiDamian Czapiewski

446314




446314












  • From what you describe, accessing the container on port 49160 from the host should be working. You are mapping port 8080 from inside the container, to port 49160 on the host. localhost:49160 should do it. Check the port number in the run command again?

    – Andreas Lorenzen
    Mar 6 at 23:44












  • You are following the guide here: nodejs.org/en/docs/guides/nodejs-docker-webapp - I just completed it, and I can see the "Hello world" page at localhost:49160 just fine. You need to double check everything I think. I can upload to a repo if you want to compare it?

    – Andreas Lorenzen
    Mar 7 at 0:03











  • I've done things again and still doesn't work. You can upload your one to a repo, it would be more than nice.

    – Damian Czapiewski
    Mar 7 at 0:06






  • 1





    Ok, uploaded here: github.com/aplorenzen/nodejs-docker-webapp

    – Andreas Lorenzen
    Mar 7 at 0:18






  • 1





    Aha, I am not using docker-machine at all. Just Docker for Windows

    – Andreas Lorenzen
    Mar 7 at 1:20

















  • From what you describe, accessing the container on port 49160 from the host should be working. You are mapping port 8080 from inside the container, to port 49160 on the host. localhost:49160 should do it. Check the port number in the run command again?

    – Andreas Lorenzen
    Mar 6 at 23:44












  • You are following the guide here: nodejs.org/en/docs/guides/nodejs-docker-webapp - I just completed it, and I can see the "Hello world" page at localhost:49160 just fine. You need to double check everything I think. I can upload to a repo if you want to compare it?

    – Andreas Lorenzen
    Mar 7 at 0:03











  • I've done things again and still doesn't work. You can upload your one to a repo, it would be more than nice.

    – Damian Czapiewski
    Mar 7 at 0:06






  • 1





    Ok, uploaded here: github.com/aplorenzen/nodejs-docker-webapp

    – Andreas Lorenzen
    Mar 7 at 0:18






  • 1





    Aha, I am not using docker-machine at all. Just Docker for Windows

    – Andreas Lorenzen
    Mar 7 at 1:20
















From what you describe, accessing the container on port 49160 from the host should be working. You are mapping port 8080 from inside the container, to port 49160 on the host. localhost:49160 should do it. Check the port number in the run command again?

– Andreas Lorenzen
Mar 6 at 23:44






From what you describe, accessing the container on port 49160 from the host should be working. You are mapping port 8080 from inside the container, to port 49160 on the host. localhost:49160 should do it. Check the port number in the run command again?

– Andreas Lorenzen
Mar 6 at 23:44














You are following the guide here: nodejs.org/en/docs/guides/nodejs-docker-webapp - I just completed it, and I can see the "Hello world" page at localhost:49160 just fine. You need to double check everything I think. I can upload to a repo if you want to compare it?

– Andreas Lorenzen
Mar 7 at 0:03





You are following the guide here: nodejs.org/en/docs/guides/nodejs-docker-webapp - I just completed it, and I can see the "Hello world" page at localhost:49160 just fine. You need to double check everything I think. I can upload to a repo if you want to compare it?

– Andreas Lorenzen
Mar 7 at 0:03













I've done things again and still doesn't work. You can upload your one to a repo, it would be more than nice.

– Damian Czapiewski
Mar 7 at 0:06





I've done things again and still doesn't work. You can upload your one to a repo, it would be more than nice.

– Damian Czapiewski
Mar 7 at 0:06




1




1





Ok, uploaded here: github.com/aplorenzen/nodejs-docker-webapp

– Andreas Lorenzen
Mar 7 at 0:18





Ok, uploaded here: github.com/aplorenzen/nodejs-docker-webapp

– Andreas Lorenzen
Mar 7 at 0:18




1




1





Aha, I am not using docker-machine at all. Just Docker for Windows

– Andreas Lorenzen
Mar 7 at 1:20





Aha, I am not using docker-machine at all. Just Docker for Windows

– Andreas Lorenzen
Mar 7 at 1:20












1 Answer
1






active

oldest

votes


















0














Short answer:



docker run -p 8080:8080 -d nodeapp


Explained :



When you try to access the port 49160 from within the instance, it is normal that it says that the connection is refused because this port is mapped from your container to your system. So only your system will be able to check this port.



I tried your files and I can access properly to the servers using http://localhost:49160



If you want to access to the port 8080 from your system, then change the mapping port while you're run the container :



docker run -p 8080:8080 -d nodeapp
# -p portAccessibleFromYourSystem:portYouWantToShare





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55033844%2frunning-app-contained-in-docker-container-in-system-browser%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Short answer:



    docker run -p 8080:8080 -d nodeapp


    Explained :



    When you try to access the port 49160 from within the instance, it is normal that it says that the connection is refused because this port is mapped from your container to your system. So only your system will be able to check this port.



    I tried your files and I can access properly to the servers using http://localhost:49160



    If you want to access to the port 8080 from your system, then change the mapping port while you're run the container :



    docker run -p 8080:8080 -d nodeapp
    # -p portAccessibleFromYourSystem:portYouWantToShare





    share|improve this answer



























      0














      Short answer:



      docker run -p 8080:8080 -d nodeapp


      Explained :



      When you try to access the port 49160 from within the instance, it is normal that it says that the connection is refused because this port is mapped from your container to your system. So only your system will be able to check this port.



      I tried your files and I can access properly to the servers using http://localhost:49160



      If you want to access to the port 8080 from your system, then change the mapping port while you're run the container :



      docker run -p 8080:8080 -d nodeapp
      # -p portAccessibleFromYourSystem:portYouWantToShare





      share|improve this answer

























        0












        0








        0







        Short answer:



        docker run -p 8080:8080 -d nodeapp


        Explained :



        When you try to access the port 49160 from within the instance, it is normal that it says that the connection is refused because this port is mapped from your container to your system. So only your system will be able to check this port.



        I tried your files and I can access properly to the servers using http://localhost:49160



        If you want to access to the port 8080 from your system, then change the mapping port while you're run the container :



        docker run -p 8080:8080 -d nodeapp
        # -p portAccessibleFromYourSystem:portYouWantToShare





        share|improve this answer













        Short answer:



        docker run -p 8080:8080 -d nodeapp


        Explained :



        When you try to access the port 49160 from within the instance, it is normal that it says that the connection is refused because this port is mapped from your container to your system. So only your system will be able to check this port.



        I tried your files and I can access properly to the servers using http://localhost:49160



        If you want to access to the port 8080 from your system, then change the mapping port while you're run the container :



        docker run -p 8080:8080 -d nodeapp
        # -p portAccessibleFromYourSystem:portYouWantToShare






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 2:57









        Mathieu LescaudronMathieu Lescaudron

        3,55941938




        3,55941938





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55033844%2frunning-app-contained-in-docker-container-in-system-browser%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            1928 у кіно

            Захаров Федір Захарович

            Ель Греко