Vincent Rubingh
08/13/2024, 2:23 PM{
"identifier": "<http+docker://localhost:2>d588341dbd754ab477b868ae19068c250004503fc7fa8539836dd35be4643a7",
"status_code": 0
}
There is no docker_container_block.get_docker_container_logs() functionMarvin
08/13/2024, 2:23 PMget_docker_container_logs()
directly available on the DockerContainer
block, but the functionality to retrieve logs from a Docker container is indeed possible. Here's how you can do it using the get_docker_container_logs
method.
First, you need the container ID to pull the logs from:
python
from prefect import task
from prefect_docker.containers import get_docker_container_logs
@task(name="Parse Jora Jobs", retries=0, log_prints=True)
def run_job_parser():
docker_container_block = DockerContainer.load("mediariot-docker-parser")
container_result = docker_container_block.run()
container_id = container_result.identifier.split('d')[-1] # Extract container ID
logs = get_docker_container_logs(container_id)
print(logs)
The get_docker_container_logs
function is async, so ensure your flow handles async/await appropriately if needed.
For more details, you can refer to the Prefect documentation: https://docs.prefect.io/latest/integrations/prefect-docker/containers/
If you need any more help, please let me know!