简体   繁体   中英

Cannot connect to docker container's IP on forwarded port

I am trying to set-up a simple dagster container with the following Dockerfile :

# 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"]

Concerning the dagster contents, they are pristine, I simply created a workspace within my home folder and created a dagster project according to the documentation :

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

The image is created via visual studio's extension, which translates to this command:

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'

The container is started via this command:

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

Here are the contents of the running container

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

Here's a wget -O- "http://127.0.0.1:3000" 2>&1 command's return

--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]

I am running wsl2 on a windows 11 host. I've tried accessing the dagit platform via the following URIs in my host's browser:

  • localhost:3000 (I know this is wrong)
  • 172.26.221.133:3000 (WSL's IP returned via ifconfig)
  • 172.17.0.2:3000 (The docker container IP adress, found via docker.network inspect.... )
  • 192.168.1.7:3000 (Some IP I found suggested here )

Calling http://172.17.0.2:3000 returns: The connection has timed out after 40 seconds, whereas localhost:3000 returns The connection was reset right away.

Could you advise on how to access the container's IP, and how to find it?

Try changing your last line in Dockerfile to

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

Then, you get this log

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

And check from your HOST ( after 1min ) (., ) you need more than 512m of memory to run it. Otherwise, your container may die.

http://localhost:3000/dagit_info

在此处输入图像描述

在此处输入图像描述

Dockerfile

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"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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