Download the PHP package diego-ninja/docker without Composer
On this page you can find all versions of the php package diego-ninja/docker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download diego-ninja/docker
More information about diego-ninja/docker
Files in diego-ninja/docker
Package docker
Short Description Run and manage docker containers in your php code
License MIT
Homepage https://github.com/diego-ninja/docker
Informations about the package docker
🐋 Docker for PHP
[]()
[
]()
[
]()
[
]()
This package provides a fluent, modern API to start and manage Docker containers directly from your PHP code. It is a fork of spatie/docker with significant improvements in ergonomics, security, and functionality.
Key Features
- ✅ Ergonomic Facade API: A static
Dockerfacade that simplifies container creation (Docker::nginx()->start()). - ✅ Type-Safe: Thanks to PHP 8.4 and the intensive use of immutable Value Objects (
ImageName,ContainerPath,Port) to validate all inputs. - ✅ Secure: Prevents command injection by validating all parameters through Value Objects.
- ✅ SSH Agent Forwarding: Securely allows containers to access the host's SSH keys.
- ✅ Extensible: Register your own custom services on the
Facadeto reuse configurations. - ✅ Well-Tested: Over 95% test coverage.
Installation
You can install the package via Composer. It requires PHP 8.4 or higher.
Quick Start
The easiest way to use the package is through the Docker facade.
Key Differences with spatie/docker
This package is a fork of spatie/docker, but it introduces significant improvements:
-
Facade for a Simplified API: The
Dockerfacade provides a static, expressive, and easy-to-remember API, ideal for frameworks like Laravel or for quick usage. -
Type Safety with Value Objects: Instead of using raw strings and numbers, the library uses Value Objects to validate every parameter, preventing common errors and attacks.
- Specific Exceptions: More descriptive exceptions, like
CouldNotStartDockerContainer, have been added to make debugging easier.
Detailed Usage
1. Using the Facade (Recommended)
The Docker facade offers three ways to create containers:
a) Shortcuts for Common Services
It includes shortcuts for the most popular services with pre-defined configurations.
You can pass a configuration array to customize the service:
b) Generic container() Builder
For any image that doesn't have a shortcut, use the container() method.
c) Registering Custom Services
You can register your own shortcuts, for example, in your application's bootstrap file.
2. Fluent API
All facade methods return a DockerContainer instance, so you can continue to use the fluent API to override or add configurations.
3. Configuration Examples
Port Mapping
Use port(hostPort, containerPort).
Volume Mapping
-
Bind Mount: Mounts a host path into the container.
- Named Volume: Uses a Docker-managed volume.
Environment Variables
4. Interacting with Running Containers
The start() method returns a DockerContainerInstance.
You can also connect to an already running container.
Testing
Before running the tests for the first time, you need to build the Docker image for testing:
Then, you can run the full test suite with Pest:
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING.md for details. Contributions are welcome.
Security
If you've found a security vulnerability, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see the License File for more information.