无法连接到转发端口上的Docker容器IP

icomxhvb  于 2022-12-29  发布在  Docker
关注(0)|答案(1)|浏览(225)

我尝试使用以下Dockerfile设置一个简单的dagster容器:

# For more information, please refer to https://aka.ms/vscode-docker-python
FROM --platform=linux/amd64 python:3.8-slim

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1

ENV DAGSTER_HOME=/dagster
ENV DAGIT_HOME=0.0.0.0

# Install pip requirements
COPY requirements.txt .
RUN python -m pip install -r requirements.txt

WORKDIR /dagster
COPY ./dagster-sample /dagster

# Creates a non-root user with an explicit UID and adds permission to access the /dagster folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" dagsteruser && chown -R dagsteruser /dagster
USER dagsteruser

EXPOSE 3000
# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["dagit", "-p", "3000"]

关于dagster的内容,它们是原始的,我只是在我的主文件夹中创建了一个工作区,并根据documentation创建了一个dagster项目:

pip install dagster
dagster project scaffold --name my-dagster-project

该图像是通过visual studio的扩展创建的,该扩展转换为以下命令:

docker image build --pull --file '/home/user1/workspaces/dagster-sample-wrapper/Dockerfile' --tag 'dagstersamplewrapper:latest' --label 'com.microsoft.created-by=visual-studio-code' '/home/user1/workspaces/dagster-sample-wrapper'

容器通过以下命令启动:

docker run -d -p 3000:3000 -it dagstersamplewrapper

以下是正在运行的容器的内容

2022-12-26 03:32:29 2022-12-26 02:32:29 +0000 - dagster - INFO - Started Dagster code server for module dagster_sample in process 10
2022-12-26 03:32:29 
2022-12-26 03:32:29   Telemetry:
2022-12-26 03:32:29 
2022-12-26 03:32:29   As an open source project, we collect usage statistics to inform development priorities. For more
2022-12-26 03:32:29   information, read https://docs.dagster.io/install#telemetry.
2022-12-26 03:32:29 
2022-12-26 03:32:29   We will not see or store solid definitions, pipeline definitions, modes, resources, context, or
2022-12-26 03:32:29   any data that is processed within solids and pipelines.
2022-12-26 03:32:29 
2022-12-26 03:32:29   To opt-out, add the following to $DAGSTER_HOME/dagster.yaml, creating that file if necessary:
2022-12-26 03:32:29 
2022-12-26 03:32:29     telemetry:
2022-12-26 03:32:29       enabled: false
2022-12-26 03:32:29 
2022-12-26 03:32:29 
2022-12-26 03:32:29   Welcome to Dagster!
2022-12-26 03:32:29 
2022-12-26 03:32:29   If you have any questions or would like to engage with the Dagster team, please join us on Slack
2022-12-26 03:32:29 
2022-12-26 03:32:29 2022-12-26 02:32:29 +0000 - dagit - INFO - Serving dagit on http://127.0.0.1:3000 in process 1

下面是我在容器中运行的wget -O- "http://127.0.0.1:3000" 2>&1命令的输出

--2022-12-26 03:53:59--  http://127.0.0.1:3000/
Connecting to 127.0.0.1:3000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 900 [text/html]
Saving to: ‘STDOUT’
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="theme-color" content="#000000"/><script type="application/json" id="initialization-data">{"pathPrefix": "", "telemetryEnabled": "True"}</script><script nonce="03fa0b7cb58d417ca2662ec5d0ed2c68">__webpack_nonce__="03fa0b7cb58d417ca2662ec5d0ed2c68"</script><link rel="manifest" href="/manifest.json" crossorigin="use-credentials"/><link rel="icon" type="image/png" href="/favicon.png"/><link rel="icon" type="image/svg+xml" href="/favicon.svg"/><title>Dagit</title><script defer="defer" src="/static/js/main.e20f9d2d.js" nonce="03fa0b7cb58d417ca2662ec5d0ed2c68"></script><link href="/static/css/main.24e9b352.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
     0K                                                       100%  284M=0s

2022-12-26 03:53:59 (284 MB/s) - written to stdout [900/900]

我在Windows 11主机上运行wsl2。我尝试通过我的主机浏览器中的以下URI访问dagit平台:

  • localhost:3000(我知道这是错误的)
  • 172.26.221.133:3000(通过ifconfig返回的WSL的IP地址)
  • 172.17.0.2:3000(通过docker inspect --format '{{ .NetworkSettings.IPAddress }}' <CONTAINER ID>找到的码头集装箱IP地址)
  • 192.168.1.7:3000(我找到的一些IP建议使用here
  • 192.168.99.100:3000(我找到的一些IP建议使用here

调用http://172.17.0.2:3000返回:The connection has timed out,而localhost:3000会立即返回The connection was reset
你能告诉我如何访问集装箱的IP地址,以及如何找到它吗?

c2e8gylq

c2e8gylq1#

尝试将Dockerfile中的最后一行更改为

#CMD ["dagit", "-p", "3000"]
ENTRYPOINT ["dagit", "-h", "0.0.0.0", "-p", "3000"]

然后你得到了这个日志

2022-12-26 04:17:21 +0000 - dagit - INFO - Serving dagit on http://0.0.0.0:3000 in process 1

然后在你的主机上检查(1分钟后)(!!)你需要超过512 M的内存来运行它。否则,你的容器可能会死。
网址:http://localhost:3000数据库信息

停靠文件

FROM --platform=linux/amd64 python:3.8-slim
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /dagster

# Install pip requirements
RUN pip install dagster
RUN dagster project from-example \
  --name my-dagster-project \
  --example quickstart_etl

RUN cd my-dagster-project && pip install -e ".[dev]"

 

WORKDIR /dagster/my-dagster-project
RUN touch dagster.yaml  #just to avoid warnings
ENV DAGSTER_HOME=/dagster/my-dagster-project 
#ENV DAGIT_HOME=0.0.0.0
EXPOSE 3000
ENTRYPOINT ["dagit", "-h", "0.0.0.0", "-p", "3000"]

如何找到集装箱的IP?

docker inspect --format '{{ .NetworkSettings.IPAddress }}' CONTAINER_NAME

通常情况下,不需要通过ip直接访问一个container,如果有多个container,并且它们必须交互,则通常使用网络https://docs.docker.com/config/containers/container-networking/
您可以设置从主机到容器

的任何端口
更多详情请点击此处:From inside of a Docker container, how do I connect to the localhost of the machine?

相关问题