Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run flows if docker agent is started with the network option #2638

Closed
ManuelMourato25 opened this issue May 22, 2020 · 6 comments · Fixed by #5748
Closed

Cannot run flows if docker agent is started with the network option #2638

ManuelMourato25 opened this issue May 22, 2020 · 6 comments · Fixed by #5748
Labels
bug Something isn't working component:agent Related to the flow submitting agent needs:details Blocked by a need for more info from user

Comments

@ManuelMourato25
Copy link

Description

Every time I try to run a flow using a docker agent with the network option specified, like so:

# Custom bridge network
prefect agent start docker -l docker-execs-test --show-flow-logs --network test-network
# Network used by Prefect services
prefect agent start docker -l docker-execs-test --show-flow-logs --network prefect-server
# Host network
prefect agent start docker -l docker-execs-test --show-flow-logs --network host

I get the following error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 392, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.6/http/client.py", line 1262, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1308, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1257, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1036, in _send_outp ut
    self.send(msg)
  File "/usr/local/lib/python3.6/http/client.py", line 974, in send
    self.connect()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 187, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 167, in _new_conn
    % (self.host, self.timeout),
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPConnection object at 0x7fb645a37cf8>, 'Connection to host.docker.internal timed out. (connect timeout=30)')

Reproduction

  1. In order to reproduce, create any flow and store it in a docker storage like so:
# Define a flow and save it in a test_flow variable
....
task_sequence = [task1,task2]
test_flow.chain(*task_sequence)

storage = Docker(image_name="flows-storage", image_tag="v1.0",local_image=True)
storage.build()
test_flow.storage=storage
test_flow.register(build=False,labels=['docker-execs-test'])

The image is created with no issues.

  1. Then start a docker agent like so:
prefect agent start docker -l docker-execs-test --show-flow-logs --network host
  1. Go to the UI and run the registered flow

  2. You should see the behaviour mentioned above.

Environment

{
"config_overrides": {},
"env_vars": [
"PREFECT__CLOUD__AGENT__LEVEL"
],
"system_information": {
"platform": "Linux-4.15.0-91-generic-x86_64-with-debian-buster-sid",
"prefect_version": "0.10.7",
"python_version": "3.6.10"
}
}

@joshmeek
Copy link

Thanks for opening @ManuelMourato25!

@joshmeek joshmeek added component:agent Related to the flow submitting agent bug Something isn't working labels May 22, 2020
@joshmeek
Copy link

Hey @ManuelMourato25 is this still an issue for you?

@ericwong3
Copy link

ericwong3 commented Jun 8, 2021

@joshmeek apparently the issue is still here, experienced similar issue today.

Same issue, when an agent is started with prefect agent docker start --network host, and a flow is executed on that agent, the flow will fail and the flow log will say requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.18.61', port=4200): Max retries exceeded with url: /graphql (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f8b253f8f50>: Failed to establish a new connection: [Errno 101] Network is unreachable'))

@zanieb
Copy link
Contributor

zanieb commented Jun 8, 2021

@ericwong3 Are you running Prefect Server? If so, are you also running it in that network? This looks like a different issue than above, here it can't connect to the backend API.

@zanieb zanieb added the needs:details Blocked by a need for more info from user label Jun 8, 2021
@ericwong3
Copy link

Yes I am running prefect server. The server and agent is started separately. The server is started with prefect server start*, and the client is started on the same host with prefect agent docker start --network host --api http://192.168.18.61:4200.

192.168.18.61 is the docker host's IP, so a container is running with bridge or host network should both be able to connect. Except it only starts without --network host, and removing it does make the issue disappear.

* I did prefect server config --use-volume > docker-compse.yml, changed pg_data mount location, and did docker-compose up, guess that is no different from doing prefect server start in relation to this issue.

@zanieb
Copy link
Contributor

zanieb commented May 2, 2022

I'm going to track a fix to this in #4840 — the issue is that the "host" network requires a change in container network mode as well.

zanieb added a commit that referenced this issue May 3, 2022
This brings our behavior in-line with the Docker CLI which will
change the network mode on created containers to 'host' or 'none'
respectively if the special network names 'host' or 'none' are used.

These networks appear to be immutably defined by Docker.

'host' networking is still not expected to work on non-Linux systems,
see the Docker documentation for more information.

Closes #4840
Closes #2638
zanieb added a commit that referenced this issue May 4, 2022
…5748)

* Add inference of Docker network mode for 'host' and 'none' networks

This brings our behavior in-line with the Docker CLI which will
change the network mode on created containers to 'host' or 'none'
respectively if the special network names 'host' or 'none' are used.

These networks appear to be immutably defined by Docker.

'host' networking is still not expected to work on non-Linux systems,
see the Docker documentation for more information.

Closes #4840
Closes #2638

* Add changes entry

* Fix Dask type-check CI error

* Fix dask import -.-

* Use `in` instead of two equality checks

Co-authored-by: Jonathan Yu <jawnsy@cpan.org>

Co-authored-by: Jonathan Yu <jawnsy@cpan.org>
lance0805 pushed a commit to hyl2015/prefect that referenced this issue Aug 2, 2022
…refectHQ#5748)

* Add inference of Docker network mode for 'host' and 'none' networks

This brings our behavior in-line with the Docker CLI which will
change the network mode on created containers to 'host' or 'none'
respectively if the special network names 'host' or 'none' are used.

These networks appear to be immutably defined by Docker.

'host' networking is still not expected to work on non-Linux systems,
see the Docker documentation for more information.

Closes PrefectHQ#4840
Closes PrefectHQ#2638

* Add changes entry

* Fix Dask type-check CI error

* Fix dask import -.-

* Use `in` instead of two equality checks

Co-authored-by: Jonathan Yu <jawnsy@cpan.org>

Co-authored-by: Jonathan Yu <jawnsy@cpan.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working component:agent Related to the flow submitting agent needs:details Blocked by a need for more info from user
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants