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

ContainerLogs endpoint always returns NULL #19

Open
rodrigoaguilera opened this issue Jan 23, 2022 · 3 comments
Open

ContainerLogs endpoint always returns NULL #19

rodrigoaguilera opened this issue Jan 23, 2022 · 3 comments

Comments

@rodrigoaguilera
Copy link
Collaborator

When I run

docker run --name test busybox:latest echo hello

I can see the output in the logs with

docker logs test

but running

$logs = $docker->containerLogs('test', ['stdout' => true]);

never returns anything.

I did a bit of debugging of the ContainerLogs.php class and it seems it expects the body to be JSON but the is received as a string
https://github.com/beluga-php/docker-php-api/blob/main/src/Endpoint/ContainerLogs.php#L83

@flavioheleno
Copy link
Member

Great findings @rodrigoaguilera ! I'll take a look at it.

@Rid
Copy link
Member

Rid commented Oct 18, 2023

This should work using the following:

$logs = $docker->containerLogs('test', ['stdout' => true], \Docker\API\Runtime\Client\Client::FETCH_RESPONSE)->getBody()->getContents();

@Rid Rid closed this as completed Oct 18, 2023
@rodrigoaguilera
Copy link
Collaborator Author

rodrigoaguilera commented Feb 17, 2024

Since the FETCH_RESPONSE is deprecated now in jane the proper way would be:

use Docker\API\Endpoint\ContainerLogs;

$docker->executeRawEndpoint(new ContainerLogs($containerCreateResult->getId(), ['stdout' => true]))->getBody()->getContents();

See #65

This skips the custom endpoint Docker\Endpoint\ContainerLogs and uses the endpoint from the generated API.
This is because that endpoint returns a content-type application/vnd.docker.multiplexed-stream for me, never a application/vnd.docker.raw-stream like the custom endpoint expects even when I set the header Accept: application/vnd.docker.raw-stream.

I'm reopening because of this issue. The custom AND the jane-generated endpoints seem to be useless to get the logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants