https://prefect.io logo
r

Raffi Utama

09/16/2023, 5:35 PM
Hii, i got an error when trying to run this code from
prefect-docker
docs:
Copy code
from prefect import flow, get_run_logger
from prefect_docker.images import pull_docker_image
from prefect_docker.containers import (
    create_docker_container,
    start_docker_container,
    get_docker_container_logs,
    stop_docker_container,
    remove_docker_container,
)


@flow
def docker_flow():
    logger = get_run_logger()
    pull_docker_image("prefecthq/prefect", "latest")
    container = create_docker_container(
        image="prefecthq/prefect", command="echo 'hello world!' && sleep 60"
    )
    start_docker_container(container_id=container.id)
    logs = get_docker_container_logs(container_id=container.id)
    <http://logger.info|logger.info>(logs)
    stop_docker_container(container_id=container.id)
    remove_docker_container(container_id=container.id)
    return container
The error says:
Copy code
Traceback (most recent call last):
  File "/home/me/repoGit/prefect/flows/docker.py", line 2, in <module>
    from prefect_docker.images import pull_docker_image
  File "/home/me/repoGit/prefect-docker/prefect_docker/__init__.py", line 2, in <module>
    from .host import DockerHost  # noqa
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/me/repoGit/prefect-docker/prefect_docker/host.py", line 10, in <module>
    class _ContextManageableDockerClient(docker.DockerClient):
                                         ^^^^^^^^^^^^^^^^^^^
AttributeError: module 'docker' has no attribute 'DockerClient'
But, i verify by running the command
from prefect_docker.images import pull_docker_image
on python interactive it doesn't show an error. This issue is similar to https://prefect-community.slack.com/archives/CL09KU1K7/p1692901876623859. I've search on the discourse forum, github issue not find a solution. How to solve this?
r

Ryan Peden

09/18/2023, 3:51 AM
It might just be because your code is in a file named
docker.py
so when it tries to lead the
docker
package it gets your file instead of what it was expecting. Does it work if you rename your file to something other than
docker.py
?