Hi guys ! I’m trying to setup a `Prefect Agent` an...
# prefect-community
a
Hi guys ! I’m trying to setup a
Prefect Agent
and a
prefect server
on my local computer, everything residing inside of
containers
. My
Prefect Server
`container(s)`is based on the
docker-compose
file retrieved from
prefect server config > server-docker-compose.yaml
. When spinning up a container for an Agent and running
prefect agent local start --api <http://host.docker.internal:4200>
, it says that I must be authenticated to communicate with the containerized server living in my local machine. My first question is: Is
authentication
mandatory in this kind of situation , for local run ? When I authenticate by creating a new tenant using
prefect server create-tenant -n default
outside the Agent container, I’m able to spin up the
Agent Container
and run everything. The problem is that I wanted to run the
create-tenant
inside the container too, but it’s not possible as I’m getting connection refused between containers.
k
Authentication is not required for server. Maybe your backend is not set right? You can do
Copy code
prefect backend server
Or is the authentication not related to Prefect? Is it more of a Docker thing?
a
I do that , but it prints this message:
Copy code
❯ docker logs -f 280822429c41
Backend switched to server
[2022-05-05 17:52:29,688] INFO - agent | Registering agent...
Traceback (most recent call last):
  File "/usr/local/bin/prefect", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/prefect/cli/agent.py", line 170, in start
    start_agent(LocalAgent, import_paths=list(import_paths), **kwargs)
  File "/usr/local/lib/python3.7/site-packages/prefect/cli/agent.py", line 128, in start_agent
    agent.start()
  File "/usr/local/lib/python3.7/site-packages/prefect/agent/agent.py", line 186, in start
    self._setup_api_connection()
  File "/usr/local/lib/python3.7/site-packages/prefect/agent/agent.py", line 870, in _setup_api_connection
    self.client.attach_headers({"X-PREFECT-AGENT-ID": self._register_agent()})
  File "/usr/local/lib/python3.7/site-packages/prefect/agent/agent.py", line 831, in _register_agent
    agent_config_id=self.agent_config_id,
  File "/usr/local/lib/python3.7/site-packages/prefect/client/client.py", line 1782, in register_agent
    tenant_id=self.tenant_id,
  File "/usr/local/lib/python3.7/site-packages/prefect/client/client.py", line 273, in tenant_id
    self._tenant_id = self._get_default_server_tenant()
  File "/usr/local/lib/python3.7/site-packages/prefect/client/client.py", line 194, in _get_default_server_tenant
    "Your Prefect Server instance has no tenants. "
prefect.exceptions.ClientError: Your Prefect Server instance has no tenants. Create a tenant with `prefect server create-tenant`
For extra context, this is the agent piece on my
docker-compose
:
Copy code
prefect_agent:
    image: "prefecthq/prefect:latest"
    command: bash -c 'prefect backend server && prefect agent local start --api <http://host.docker.internal:4200>'
    networks:
      prefect-server: null
    depends_on:
      apollo:
        condition: service_started
k
Ah you just need to create the tenant before the agent start?
a
Yes, my problem is , where should I do this based on the my compose file retrieved from:
prefect server config > server-docker-compose.yaml
. Can it be done in
Apollo
,
GraphQL
containers or somewhere else?
k
Not sure but maybe:
Copy code
command: bash -c 'prefect backend server && prefect server create-tenant && prefect agent local start --api <http://host.docker.internal:4200>'
a
Tried with the
-n default
flag too but no luck also 😕 This is weird, sorry ! Docker-compose:
Copy code
prefect_agent:
  image: "prefecthq/prefect:0.15.7-python3.9"
  command: bash -c "prefect backend server && prefect server create-tenant && prefect agent local start --api <http://host.docker.internal:4200>"
  networks:
    prefect-server: null
  depends_on:
    apollo:
      condition: service_started
k
Oh sorry I forgot there is this repo where a community member did it. Maybe you can look there for inspiration
Looks like he created the tenant ahead of time though
a
Thank you ! I was able then to create the tenant inside the container by setting the
network_mode
to
host
in the agent dockerfile part. Huge thanks for all the help and for sharing this project @Kevin Kho
k
Nice work! Glad you figured it out
130 Views