我正在构建并启动它:
sudo docker build -t docker_mads_dask_server ~/docker_setups/dask_cluster
echo "Stop/Remove dask_server"
sudo docker stop dask_server -t5
sudo docker rm dask_server
echo "Build tag"
sudo docker build --tag mads_servers.dask_server:0.1.2 ~/docker_setups/dask_cluster
sudo docker run --publish 0.0.0.0:8710:8710 --publish 0.0.0.0:8711:8711 --detach --name dask_server mads_servers.dask_server:0.1.2
我实际上可以看到它的运行方式:
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a29f89f6929f mads_servers.dask_server:0.1.2 "python3 /code/mads/…" 4 minutes ago Up 4 minutes 0.0.0.0:8710-8711->8710-8711/tcp, 8787/tcp dask_server
现在我连接到容器中:
$ sudo docker exec -it dask_server /bin/bash
root@a29f89f6929f
并查看连接是否打开:
# (inside container)
$ curl -vvv http://127.0.0.1:8710
[...]
< HTTP/1.1 404 Not Found
< Server: TornadoServer/6.0.4
因此,Web服务器实际上已启动并且可以在容器中[[内部访问。现在让我们从外部检查它:
# (outside container)
$ sudo netstat -tulpn | grep 87
tcp6 0 0 :::8710 :::* LISTEN 8705/docker-proxy
tcp6 0 0 :::8711 :::* LISTEN 8692/docker-proxy
端口是开放的,对tcp6有点恐惧-所以我将其更改为显式IP匹配:
--publish 192.168.56.11:8710:8710 --publish 192.168.56.11:8711:8711
并且netstat现在显示IPv4:
# (outside container) tcp 0 0 192.168.56.11:8710 0.0.0.0:* LISTEN 13039/docker-proxy tcp 0 0 192.168.56.11:8711 0.0.0.0:* LISTEN 13025/docker-proxy
但是相同的连接测试得到:
$ curl -vvv http://127.0.0.1:8710 * Rebuilt URL to: http://127.0.0.1:8710/ * Trying 127.0.0.1... * TCP_NODELAY set * Connected to 127.0.0.1 (127.0.0.1) port 8710 (#0) > GET / HTTP/1.1 > Host: 127.0.0.1:8710 > User-Agent: curl/7.58.0 > Accept: */* > * Recv failure: Connection reset by peer * stopped the pause stream! * Closing connection 0 curl: (56) Recv failure: Connection reset by peer
我的Dockerfile
:
FROM ubuntu:20.04 FROM python:3.8 RUN apt update && apt install -y cowsay tmux vim net-tools iotop RUN python -m pip install pandas numpy dask distributed redis sqlalchemy tornado cloudpickle RUN python -m pip install dask[dataframe] --upgrade ADD code/ /code/ # Dashboard port EXPOSE 8710 # Scheduler port EXPOSE 8711 EXPOSE 8787 CMD ["python3", "/code/mads/mads_pkg/mads_servers/dask_server.py"]
为什么
dask-proxy
不将其转发到容器的暴露端口?
localhost
。从主机上,您可以在暴露端口的同时使用localhost来执行curl命令,但是当使用另一个容器时,应该使用另一个容器名称来连接或找到它的IP并与其连接。
根据您的评论,您获得了内部容器IP,但是您尝试从主机进行连接,而从其他容器内部不再进行连接。
通常,您可以将--publish 0.0.0.0:8711:8711
替换为--publish 8711:8711
,因为默认情况下docker将在所有IP上发布端口。