-1

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 output that I ran inside the container

--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 inspect --format '{{ .NetworkSettings.IPAddress }}' <CONTAINER ID>)
  • 192.168.1.7:3000 (Some IP I found suggested here)
  • 192.168.99.100: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?

EDIT: I have searched for a while, but could not find a use-case where dagit is accessed by anything else except dagit -h 0.0.0.0...

Imad
  • 2,358
  • 5
  • 26
  • 55
  • check https://www.freecodecamp.org/news/how-to-get-a-docker-container-ip-address-explained-with-examples/ , and verify your docker network config – Mate Dec 26 '22 at 02:54
  • Yes I read this, unless I misunderstood something, this is how I got `172.17.0.2`. – Imad Dec 26 '22 at 02:56
  • Verify if "dagit" is runnig ok INSIDE your container, with curl or wget. – Mate Dec 26 '22 at 03:01
  • maybe! try `curl http://127.0.0.1:3000` inside your container, check response and logs – Mate Dec 26 '22 at 03:16
  • The wget seems to return a `200` HTTP code – Imad Dec 26 '22 at 03:24
  • One important difference that I just noticed, calling `http://172.17.0.2:3000/` returns a `The connection has timed out` after 40 seconds, whereas `localhost:3000` returns `The connection was reset`. I will include this in my post – Imad Dec 26 '22 at 03:32
  • 1
    Pls, try `wget -O- 'http://127.0.0.1:3000' 2>&1` and add the result – Mate Dec 26 '22 at 03:43

1 Answers1

1

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

enter image description here

enter image description here

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

How to find container's IP ?

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

enter image description here

Normally it is not necessary to access a container by ip directly. If you have several containers and they must interact, it is usual to use a network https://docs.docker.com/config/containers/container-networking/

You could set any port from host to container enter image description here

More detail here: From inside of a Docker container, how do I connect to the localhost of the machine?

Mate
  • 4,976
  • 2
  • 32
  • 38
  • Thank you ! Your solution works, indeed. I am perplexed as to how it functions. How is 0.0.0.0 on the container mapped to localhost on the host machine? Also, although your solution offers a workaround, it doesn't answer the original question : ` how to access the container's IP, and how to find it?`, – Imad Dec 26 '22 at 11:55
  • 0.0.0.0 is not mapped to localhost. It's port forwarding. Why do you need to access by ip? – Mate Dec 26 '22 at 13:38
  • 1
    If you run `docker run -d -p 8383:3000 ... ` , then you'll use localhost:8383 – Mate Dec 26 '22 at 13:46
  • I think I may have expressed myself badly, I mean I want to access the **container's** localhost from my windows host (navigator), without specifying `-h 0.0.0.0` in the `dagit` command. Specifying `0.0.0.0` should be avoided, and I have a feeling dagster will use it later on for something else. – Imad Dec 27 '22 at 11:28
  • According to : https://www.howtogeek.com/225487/what-is-the-difference-between-127.0.0.1-and-0.0.0.0/ **0.0.0.0 is a non-routable meta-address used to designate an invalid, unknown, or non-applicable target (a ‘no particular address’ place holder).** – Imad Dec 27 '22 at 11:33
  • According to this, it should be possible to `curl :`, which is what is bugging me so much, why can't I do it... https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/ – Imad Dec 27 '22 at 14:36
  • I can't imagine why you want that. To avoid bad practices, maybe you could use ngrok. It's an amazing, free and very easy tool to "public" any port from localhost to the world. https://ngrok.com/ – Mate Dec 27 '22 at 21:40
  • Then, cmd on your host : ngrok http 3000 . enjoy it! – Mate Dec 27 '22 at 21:44