Thread
#prefect-community
    Tom Klein

    Tom Klein

    9 months ago
    I’m trying to create a Docker container and then run the container - using the task library docker tasks - but i think i’m running into an issue
    [16 Dec 2021 6:03am]: Error during execution of task: DockerException("Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))")
    is it related to the fact i’m using a Docker agent? or a Docker storage?
    this is the step i tried to create
    create_lichy = CreateContainer(image_name='lichy:1.0', container_name='my_lichy', command='npm run run')
    Kevin Kho

    Kevin Kho

    9 months ago
    I think the issue is trying to run Docker in Docker because the docker agent spins up a container for your Flow and then that Flow in the container is trying to spin another one. You need to mount the Docker sock for this Docker in Docker to work. Not super sure though
    Tom Klein

    Tom Klein

    9 months ago
    ya that’s what i thought though im not sure how to do that 😕
    looks like it should be something like
    -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker
    Kevin Kho

    Kevin Kho

    9 months ago
    I think you have it but here is an archived issue
    This user said they got it with
    -v /var/run/docker.sock:/var/run/docker.sock
    on the agent run command I think
    Tom Klein

    Tom Klein

    9 months ago
    hmm, ya i was just looking for which docker to put it on, quite a few flying around
    i’ll try that 🙂
    they say they put it on the
    docker run
    though… not sure that’s the agent
    Kevin Kho

    Kevin Kho

    9 months ago
    I saw that but I don’t think you use
    docker run
    anywhere when you do this, and the agent takes in the
    volume
    argument also
    Tom Klein

    Tom Klein

    9 months ago
    hah. it worked
    btw, i only saw examples for logging from tasks, is there no way to use the prefect.context in the flow?
    Kevin Kho

    Kevin Kho

    9 months ago
    No because the Flow block is not deferred. Only tasks are. So a logging statement in the Flow block gets executed at registration time
    Tom Klein

    Tom Klein

    9 months ago
    ah i see, so i guess i should just create like a
    print_log
    task or something if i need to ? (since otherwise i have no way of logging task-library tasks) in any case:
    ListContainers
    - for whatever reason, this one behaves really weird, while all its siblings behave fine it forces me to do
    .run()
    on the class, otherwise it behaves as if just running the task returns the class or something…
    create_lichy = CreateContainer(image_name='lichy:1.0', container_name='my_lichy', command='npm run run',log_stdout=True)
    run_lichy = StartContainer(log_stdout=True)
    wait_on_lichy = WaitOnContainer(log_stdout=True)
    list_lichy = ListContainers(all_containers=True, filters={"name":"my_lichy"}, log_stdout=True)
    lichy_logs = GetContainerLogs(log_stdout=True)
    Kevin Kho

    Kevin Kho

    9 months ago
    yes or log inside the task
    Tom Klein

    Tom Klein

    9 months ago
    lichy_list = list_lichy()
        if len(lichy_list) == 0:
            lichy_id = create_lichy()
            print_stuff(f"Lichy container does not exist, created one with id: {lichy_id}")
        else:
            lichy_id = lichy_list[0].get('Id')
            print_stuff(f"Lichy containr already exists, id: {lichy_id}")
        run_lichy(container_id=lichy_id)
        lichy_res = wait_on_lichy(container_id=lichy_id)
        print_stuff(lichy_res)
    logging inside the task is impossible when it’s not my task, right?
    in any case, first line there ^ if i don’t add
    .run()
    it complains:
    ~/Prefect/hb-prefect$ python3 build.py 
    
    Traceback (most recent call last):
      File "build.py", line 2, in <module>
        from flows import xkcd, hello, seg_pred_backfill
      File "/home/ubuntu/Prefect/hb-prefect/flows/seg_pred_backfill.py", line 80, in <module>
        if len(lichy_list) == 0:
    TypeError: object of type 'ListContainers' has no len()
    Kevin Kho

    Kevin Kho

    9 months ago
    Ah I see what you mean. Yeah. You can’t use
    if
    inside the Flow block because it’s not a task so it’s executed immediately. You need to use the
    case
    task instead
    Tom Klein

    Tom Klein

    9 months ago
    this error goes away if i do
    .run()
    , but --- then i don’t see the task in the cloud UI….?
    oh interesting
    but why would it not appear in the cloud UI if it actually ran?
    Kevin Kho

    Kevin Kho

    9 months ago
    Because .
    run()
    forces the run during your registration I think and it becomes registered with whatever the list was as a constant
    Tom Klein

    Tom Klein

    9 months ago
    ok that makes sense, interesting that just the fact i was using
    if
    seemed to make the IDE complain about the type mismatch 🤔 (prompting me to add the
    .run()
    )