Ping Docker Container from another machine in the network

后端 未结 1 862
醉话见心
醉话见心 2021-01-01 02:17

I have created a docker container and tried pinging www.google.com within the bash of the container and it works. Also I tried pinging the container from the host - it works

相关标签:
1条回答
  • 2021-01-01 02:59

    You cannot ping a Docker container from an external host by default (to do so, you would have to ensure that the Docker network bridge -docker0- has an IP Address, and you would have to configure routes on your other hosts to use you Docker host as a gateway for the bridge address range).

    By default, any service running inside a Docker container is not "Published" (Docker terminology) and cannot be reached from outside. You have to explicitly define/allow the services you want to be published when you run your container.

    For example, to publish your container's Tomcat app (supposing it is configured to listen on port 8080) to port 80 on the host, you would run your container using the -p option :

        docker run -d -p 80:8080 my-tomcat-image:tag 
    

    But if you only want to access Tomcat from other containers on the same host, you don't need to configure anything.

    0 讨论(0)
提交回复
热议问题