Can't connect to Node inside Docker image












1















I've created an image using this Docker file...



FROM node:8

# Create application directory
WORKDIR /usr/src/app

# Install application dependencies
# By only copying the package.json file here, we take advantage of cached Docker layers
COPY package.json ./
RUN npm install
# This will install dev dependencies as well.
# If dev dependencies have been set, use --only-production when deploying to production

# Bundle app source code
COPY . .

EXPOSE 3000

CMD ["node", "server.js"]


But when I run it using $ docker run -d --rm -p 3000:3000 62 I can't cUrl the API running inside the container from the Docker host (OS X) using curl http://localhost:3000/About



If I exec into the container I get a valid response from the API via cUrl. Looks like a Linux firewall in the container but I don't see one running.



any ideas?










share|improve this question


















  • 1





    Are there any interesting log messages? Can you share enough application code to make a Minimal, Complete, and Verifiable example? Is stackoverflow.com/a/26679878/10008173 relevant to you?

    – David Maze
    Nov 25 '18 at 12:56











  • Thanks for steering me in the right direction... server.js was using localhost as the host

    – Octo
    Nov 25 '18 at 14:09
















1















I've created an image using this Docker file...



FROM node:8

# Create application directory
WORKDIR /usr/src/app

# Install application dependencies
# By only copying the package.json file here, we take advantage of cached Docker layers
COPY package.json ./
RUN npm install
# This will install dev dependencies as well.
# If dev dependencies have been set, use --only-production when deploying to production

# Bundle app source code
COPY . .

EXPOSE 3000

CMD ["node", "server.js"]


But when I run it using $ docker run -d --rm -p 3000:3000 62 I can't cUrl the API running inside the container from the Docker host (OS X) using curl http://localhost:3000/About



If I exec into the container I get a valid response from the API via cUrl. Looks like a Linux firewall in the container but I don't see one running.



any ideas?










share|improve this question


















  • 1





    Are there any interesting log messages? Can you share enough application code to make a Minimal, Complete, and Verifiable example? Is stackoverflow.com/a/26679878/10008173 relevant to you?

    – David Maze
    Nov 25 '18 at 12:56











  • Thanks for steering me in the right direction... server.js was using localhost as the host

    – Octo
    Nov 25 '18 at 14:09














1












1








1


0






I've created an image using this Docker file...



FROM node:8

# Create application directory
WORKDIR /usr/src/app

# Install application dependencies
# By only copying the package.json file here, we take advantage of cached Docker layers
COPY package.json ./
RUN npm install
# This will install dev dependencies as well.
# If dev dependencies have been set, use --only-production when deploying to production

# Bundle app source code
COPY . .

EXPOSE 3000

CMD ["node", "server.js"]


But when I run it using $ docker run -d --rm -p 3000:3000 62 I can't cUrl the API running inside the container from the Docker host (OS X) using curl http://localhost:3000/About



If I exec into the container I get a valid response from the API via cUrl. Looks like a Linux firewall in the container but I don't see one running.



any ideas?










share|improve this question














I've created an image using this Docker file...



FROM node:8

# Create application directory
WORKDIR /usr/src/app

# Install application dependencies
# By only copying the package.json file here, we take advantage of cached Docker layers
COPY package.json ./
RUN npm install
# This will install dev dependencies as well.
# If dev dependencies have been set, use --only-production when deploying to production

# Bundle app source code
COPY . .

EXPOSE 3000

CMD ["node", "server.js"]


But when I run it using $ docker run -d --rm -p 3000:3000 62 I can't cUrl the API running inside the container from the Docker host (OS X) using curl http://localhost:3000/About



If I exec into the container I get a valid response from the API via cUrl. Looks like a Linux firewall in the container but I don't see one running.



any ideas?







docker






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 11:55









OctoOcto

223




223








  • 1





    Are there any interesting log messages? Can you share enough application code to make a Minimal, Complete, and Verifiable example? Is stackoverflow.com/a/26679878/10008173 relevant to you?

    – David Maze
    Nov 25 '18 at 12:56











  • Thanks for steering me in the right direction... server.js was using localhost as the host

    – Octo
    Nov 25 '18 at 14:09














  • 1





    Are there any interesting log messages? Can you share enough application code to make a Minimal, Complete, and Verifiable example? Is stackoverflow.com/a/26679878/10008173 relevant to you?

    – David Maze
    Nov 25 '18 at 12:56











  • Thanks for steering me in the right direction... server.js was using localhost as the host

    – Octo
    Nov 25 '18 at 14:09








1




1





Are there any interesting log messages? Can you share enough application code to make a Minimal, Complete, and Verifiable example? Is stackoverflow.com/a/26679878/10008173 relevant to you?

– David Maze
Nov 25 '18 at 12:56





Are there any interesting log messages? Can you share enough application code to make a Minimal, Complete, and Verifiable example? Is stackoverflow.com/a/26679878/10008173 relevant to you?

– David Maze
Nov 25 '18 at 12:56













Thanks for steering me in the right direction... server.js was using localhost as the host

– Octo
Nov 25 '18 at 14:09





Thanks for steering me in the right direction... server.js was using localhost as the host

– Octo
Nov 25 '18 at 14:09












1 Answer
1






active

oldest

votes


















2














Your node server is most likely not listening on all interfaces, make sure it binds to 0.0.0.0 instead of 127.0.0.1






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%2f53467164%2fcant-connect-to-node-inside-docker-image%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









    2














    Your node server is most likely not listening on all interfaces, make sure it binds to 0.0.0.0 instead of 127.0.0.1






    share|improve this answer




























      2














      Your node server is most likely not listening on all interfaces, make sure it binds to 0.0.0.0 instead of 127.0.0.1






      share|improve this answer


























        2












        2








        2







        Your node server is most likely not listening on all interfaces, make sure it binds to 0.0.0.0 instead of 127.0.0.1






        share|improve this answer













        Your node server is most likely not listening on all interfaces, make sure it binds to 0.0.0.0 instead of 127.0.0.1







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 14:07









        Uku LoskitUku Loskit

        30.4k86879




        30.4k86879






























            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%2f53467164%2fcant-connect-to-node-inside-docker-image%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

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)