connectholland/docker-api-bundle
## Getting Started
### Minimal Setup
1. **Installation**: Add the bundle via Composer:
```bash
composer require connectholland/docker-api-bundle
.env:
DOCKER_API_USERNAME=your_docker_username
DOCKER_API_TOKEN=your_docker_token_or_password
ConnectHolland\DockerApiBundle\Api\Client into your service/controller.
Example:
use ConnectHolland\DockerApiBundle\Api\Client;
class MyController {
public function __construct(private Client $client) {}
}
$repositories = $this->client->findRepositories('laravel');
$images = $this->client->findImages('nginx');
Client class for available methods (e.g., findRepositories, findImages).config/bundles.php (though autoloading should handle this).$results = $this->client->findRepositories('search-term');
// Process results (e.g., iterate over $results['results']).
$images = $this->client->findImages('image-name');
// Filter or fetch details from $images.
next or offset parameters if supported:
$nextPage = $this->client->findRepositories('search-term', ['page' => 2]);
try {
$data = $this->client->findRepositories('term');
} catch (\ConnectHolland\DockerApiBundle\Exception\ApiException $e) {
// Log or retry logic.
}
$cacheKey = 'docker_repos_laravel';
if (!$repos = $this->cache->get($cacheKey)) {
$repos = $this->client->findRepositories('laravel');
$this->cache->set($cacheKey, $repos, '1 hour');
}
Client to ensure testability and clarity.# config/packages/connect_holland_docker_api.yaml
connect_holland_docker_api:
registry_url: 'https://custom-registry.example.com/v2/'
Incomplete API:
docker/docker) as a fallback.Authentication Issues:
DOCKER_API_TOKEN is a password or access token (not a refresh token). Docker Hub may reject invalid tokens.curl first:
curl -u "$DOCKER_API_USERNAME:$DOCKER_API_TOKEN" https://hub.docker.com/v2/repositories/library/
Rate Limiting:
Archived Status:
DOCKER_API_DEBUG=true in .env to log API requests/responses.HttpClient or Guzzle middleware to inspect raw responses:
$this->client->getHttpClient()->getEventDispatcher()->addListener(
'request',
function (RequestEvent $event) {
// Log request details.
}
);
Client service calls.Fallback to Official SDK: For unsupported features, integrate the official Docker SDK:
composer require docker/docker
Example:
use Docker\AutomatedBuilder\DockerClient;
$client = DockerClient::create();
$images = $client->imagesList();
Environment-Specific Config: Use Symfony’s parameter bag to override settings per environment:
# config/packages/dev/connect_holland_docker_api.yaml
connect_holland_docker_api:
registry_url: 'https://registry-1.docker.io' # Override for dev
Testing:
Mock the Client in tests to avoid hitting Docker Hub:
$this->mockBuilder()
->disableOriginalConstructor()
->getMockBuilder(Client::class)
->disableOriginalConstructor()
->addMethods(['findRepositories'])
->getMock();
Extension Points:
Client to transform responses (e.g., flatten nested data).RetryStrategy.
---
How can I help you explore Laravel packages today?