无法使用 netowrk_mode 在 docker 容器中访问 jupyterhub:主机
Can't access jupyterhub in a docker container with netowrk_mode: host
由于某些要求,我在容器中有一个 jupyterhub 运行:network_mode: 主机。
但是,在将 network_mode 设置为托管在我的 docker-compose 文件中之后,我无法使用主机 ip:8000.
从外部主机访问 jupyterhub
我对this的理解是
If you use the host network mode for a container, that container’s
network stack is not isolated from the Docker host (the container
shares the host’s networking namespace), and the container does not
get its own IP-address allocated. For instance, if you run a container
which binds to port 80 and you use host networking, the container’s
application is available on port 80 on the host’s IP address.
有什么我遗漏的吗?
编辑:
为了简化,我按照说明 here
docker run --rm -d --network host --name my_nginx nginx
我可以通过
访问 nginx 欢迎页面
$ curl localhost:80
但如果我尝试从另一台主机 curl,我会得到
$ curl 10.230.0.123:80
curl: (7) Failed connect to 10.230.0.123:80; No route to host
当您的系统防火墙处于活动状态并阻止端口访问时,可能会发生此问题。您可以使用以下方式启用端口访问:
# in centos7, by updating iptables rules
iptables -I INPUT 5 -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
# in ubuntu
sudo ufw allow 80/tcp
由于某些要求,我在容器中有一个 jupyterhub 运行:network_mode: 主机。 但是,在将 network_mode 设置为托管在我的 docker-compose 文件中之后,我无法使用主机 ip:8000.
从外部主机访问 jupyterhub我对this的理解是
If you use the host network mode for a container, that container’s network stack is not isolated from the Docker host (the container shares the host’s networking namespace), and the container does not get its own IP-address allocated. For instance, if you run a container which binds to port 80 and you use host networking, the container’s application is available on port 80 on the host’s IP address.
有什么我遗漏的吗?
编辑: 为了简化,我按照说明 here
docker run --rm -d --network host --name my_nginx nginx
我可以通过
访问 nginx 欢迎页面$ curl localhost:80
但如果我尝试从另一台主机 curl,我会得到
$ curl 10.230.0.123:80
curl: (7) Failed connect to 10.230.0.123:80; No route to host
当您的系统防火墙处于活动状态并阻止端口访问时,可能会发生此问题。您可以使用以下方式启用端口访问:
# in centos7, by updating iptables rules
iptables -I INPUT 5 -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
# in ubuntu
sudo ufw allow 80/tcp