简体   繁体   English

与 Docker 的网络连接问题

[英]Issues with Network connectivity with Docker

I am facing issues configuring network in docker.我在 docker 中配置网络时遇到问题。 Details are given below.详情如下。

Host Machine:- Ubuntu Server 14.04 LTS 64-bit.主机:- Ubuntu Server 14.04 LTS 64 位。 IP subnet: 10.0.0.0/16, IP address: 10.0.0.206/16 and default gateway: 10.0.0.1/16. IP 子网:10.0.0.0/16,IP 地址:10.0.0.206/16,默认网关:10.0.0.1/16。 This machine having docker installed (version 1.6.2 build 7c8fca2) and has a default IP in the docker0 bridge of 172.17.42.1/16.这台机器安装了 docker(版本 1.6.2 build 7c8fca2)并且在 docker0 网桥 172.17.42.1/16 中有一个默认 IP。 However, the container has received the IP as 172.17.0.1.但是,容器已收到 IP 为 172.17.0.1。 Problems are as follows.问题如下。

  1. My Host machine and docker container is able to connect with each other and to Internet but any other machines are not able to connect with docker container.我的主机和 docker 容器能够相互连接并连接到 Internet,但任何其他机器都无法与 docker 容器连接。

  2. Changing the docker0 bridge IP is temporary and reverts back to 172.17.42.1/16 once every reboot.更改 docker0 网桥 IP 是暂时的,每次重新启动时都会恢复到 172.17.42.1/16。

  3. I cannot set a static IP address of my container as it changes automatically at every exit or if the host is rebooted.我无法设置容器的静态 IP 地址,因为它会在每次退出或重新启动主机时自动更改。 Checked the container's network config file /etc/network/interfaces but doing changes in this file has no effect to its eth0 interface.检查容器的网络配置文件 /etc/network/interfaces 但在此文件中进行更改对其 eth0 接口没有影响。

In very short, I am not able to connect to the container from outer world (from other physical machines) even when I have configured the networking interface of other machines to connect to docker host and container.简而言之,即使我已经配置了其他机器的网络接口以连接到 docker 主机和容器,我也无法从外部世界(从其他物理机器)连接到容器。

How can I fix this connection problem?如何解决此连接问题?

By default, Docker containers can not be accessed from other host.默认情况下,无法从其他主机访问 Docker 容器。 And the IP address is allocated by docker.并且IP地址由docker分配。

You can use "--net=host" when run containers, then the container will share the same IP address with the host node.运行容器时可以使用“--net=host”,那么容器将与主机节点共享相同的IP地址。 And the container will be available from other node.并且容器将从其他节点可用。

docker run -it --net=host ubuntu bash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM