Access Docker Container Port in a Ubuntu VM





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















Given an Ubuntu VMWare Machine (IP: 192.168.10.35) that runs a docker image inside (IP: 172.0.18.2) and given this docker-compose.yml how would I access the Docker Image from my local machine?



version: '3'

services:
sc2:
build: .
ports:
- 127.0.0.1:4620:80
restart: always
networks:
- default
volumes:
- ./sc2ai:/sc2ai
- ./apache/000-default.conf:/etc/apache2/sites-available/000-default.conf
networks:
default:


I tried to access 192.168.10.35:4620 but the connection failed. What am I missing? Is there an option in the docker-compose missing or do I need to forward ports from inside the VM to the docker image?



PS: If I start the image in docker-for-windows on my local machine I can access it via http://localhost:4620.










share|improve this question























  • You're only binding to 127.0.0.1:4620:80. Change that line to 4620:80 and what you have should work fine.

    – johnharris85
    Jan 4 at 0:46


















0















Given an Ubuntu VMWare Machine (IP: 192.168.10.35) that runs a docker image inside (IP: 172.0.18.2) and given this docker-compose.yml how would I access the Docker Image from my local machine?



version: '3'

services:
sc2:
build: .
ports:
- 127.0.0.1:4620:80
restart: always
networks:
- default
volumes:
- ./sc2ai:/sc2ai
- ./apache/000-default.conf:/etc/apache2/sites-available/000-default.conf
networks:
default:


I tried to access 192.168.10.35:4620 but the connection failed. What am I missing? Is there an option in the docker-compose missing or do I need to forward ports from inside the VM to the docker image?



PS: If I start the image in docker-for-windows on my local machine I can access it via http://localhost:4620.










share|improve this question























  • You're only binding to 127.0.0.1:4620:80. Change that line to 4620:80 and what you have should work fine.

    – johnharris85
    Jan 4 at 0:46














0












0








0








Given an Ubuntu VMWare Machine (IP: 192.168.10.35) that runs a docker image inside (IP: 172.0.18.2) and given this docker-compose.yml how would I access the Docker Image from my local machine?



version: '3'

services:
sc2:
build: .
ports:
- 127.0.0.1:4620:80
restart: always
networks:
- default
volumes:
- ./sc2ai:/sc2ai
- ./apache/000-default.conf:/etc/apache2/sites-available/000-default.conf
networks:
default:


I tried to access 192.168.10.35:4620 but the connection failed. What am I missing? Is there an option in the docker-compose missing or do I need to forward ports from inside the VM to the docker image?



PS: If I start the image in docker-for-windows on my local machine I can access it via http://localhost:4620.










share|improve this question














Given an Ubuntu VMWare Machine (IP: 192.168.10.35) that runs a docker image inside (IP: 172.0.18.2) and given this docker-compose.yml how would I access the Docker Image from my local machine?



version: '3'

services:
sc2:
build: .
ports:
- 127.0.0.1:4620:80
restart: always
networks:
- default
volumes:
- ./sc2ai:/sc2ai
- ./apache/000-default.conf:/etc/apache2/sites-available/000-default.conf
networks:
default:


I tried to access 192.168.10.35:4620 but the connection failed. What am I missing? Is there an option in the docker-compose missing or do I need to forward ports from inside the VM to the docker image?



PS: If I start the image in docker-for-windows on my local machine I can access it via http://localhost:4620.







docker ubuntu vmware ubuntu-18.04






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 4 at 0:37









PrimuSPrimuS

95111233




95111233













  • You're only binding to 127.0.0.1:4620:80. Change that line to 4620:80 and what you have should work fine.

    – johnharris85
    Jan 4 at 0:46



















  • You're only binding to 127.0.0.1:4620:80. Change that line to 4620:80 and what you have should work fine.

    – johnharris85
    Jan 4 at 0:46

















You're only binding to 127.0.0.1:4620:80. Change that line to 4620:80 and what you have should work fine.

– johnharris85
Jan 4 at 0:46





You're only binding to 127.0.0.1:4620:80. Change that line to 4620:80 and what you have should work fine.

– johnharris85
Jan 4 at 0:46












1 Answer
1






active

oldest

votes


















0














You can't, because you've explicitly declared that the container (not the image) is only reachable from the VM itself. The declaration



ports:
- 127.0.0.1:4620:80


forwards inbound connections on port 4620 on the host to port 80 in the container, but only on the interface bound to 127.0.0.1, which is the dedicated loopback interface (often named lo). When you try to contact it from the host, it arrives on the VM's external IP 192.168.10.35, but nothing is listening there.



If you remove the explicit port binding, Docker will listen on all interfaces, which is usually what you want, and then you should be able to reach the container via the VM's external IP address.



ports:
- '4620:80'


(Terminology: an image is a set of static filesystem content; you launch containers from an image and make network connections to the running containers. You can't directly see what's inside an image, an image doesn't have any running processes, and you can't connect to an image on its own.)






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%2f54031735%2faccess-docker-container-port-in-a-ubuntu-vm%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














    You can't, because you've explicitly declared that the container (not the image) is only reachable from the VM itself. The declaration



    ports:
    - 127.0.0.1:4620:80


    forwards inbound connections on port 4620 on the host to port 80 in the container, but only on the interface bound to 127.0.0.1, which is the dedicated loopback interface (often named lo). When you try to contact it from the host, it arrives on the VM's external IP 192.168.10.35, but nothing is listening there.



    If you remove the explicit port binding, Docker will listen on all interfaces, which is usually what you want, and then you should be able to reach the container via the VM's external IP address.



    ports:
    - '4620:80'


    (Terminology: an image is a set of static filesystem content; you launch containers from an image and make network connections to the running containers. You can't directly see what's inside an image, an image doesn't have any running processes, and you can't connect to an image on its own.)






    share|improve this answer




























      0














      You can't, because you've explicitly declared that the container (not the image) is only reachable from the VM itself. The declaration



      ports:
      - 127.0.0.1:4620:80


      forwards inbound connections on port 4620 on the host to port 80 in the container, but only on the interface bound to 127.0.0.1, which is the dedicated loopback interface (often named lo). When you try to contact it from the host, it arrives on the VM's external IP 192.168.10.35, but nothing is listening there.



      If you remove the explicit port binding, Docker will listen on all interfaces, which is usually what you want, and then you should be able to reach the container via the VM's external IP address.



      ports:
      - '4620:80'


      (Terminology: an image is a set of static filesystem content; you launch containers from an image and make network connections to the running containers. You can't directly see what's inside an image, an image doesn't have any running processes, and you can't connect to an image on its own.)






      share|improve this answer


























        0












        0








        0







        You can't, because you've explicitly declared that the container (not the image) is only reachable from the VM itself. The declaration



        ports:
        - 127.0.0.1:4620:80


        forwards inbound connections on port 4620 on the host to port 80 in the container, but only on the interface bound to 127.0.0.1, which is the dedicated loopback interface (often named lo). When you try to contact it from the host, it arrives on the VM's external IP 192.168.10.35, but nothing is listening there.



        If you remove the explicit port binding, Docker will listen on all interfaces, which is usually what you want, and then you should be able to reach the container via the VM's external IP address.



        ports:
        - '4620:80'


        (Terminology: an image is a set of static filesystem content; you launch containers from an image and make network connections to the running containers. You can't directly see what's inside an image, an image doesn't have any running processes, and you can't connect to an image on its own.)






        share|improve this answer













        You can't, because you've explicitly declared that the container (not the image) is only reachable from the VM itself. The declaration



        ports:
        - 127.0.0.1:4620:80


        forwards inbound connections on port 4620 on the host to port 80 in the container, but only on the interface bound to 127.0.0.1, which is the dedicated loopback interface (often named lo). When you try to contact it from the host, it arrives on the VM's external IP 192.168.10.35, but nothing is listening there.



        If you remove the explicit port binding, Docker will listen on all interfaces, which is usually what you want, and then you should be able to reach the container via the VM's external IP address.



        ports:
        - '4620:80'


        (Terminology: an image is a set of static filesystem content; you launch containers from an image and make network connections to the running containers. You can't directly see what's inside an image, an image doesn't have any running processes, and you can't connect to an image on its own.)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 4 at 0:49









        David MazeDavid Maze

        15.9k31532




        15.9k31532
































            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%2f54031735%2faccess-docker-container-port-in-a-ubuntu-vm%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

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas