PHPackages                             theod02/castor-docker-runner - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. theod02/castor-docker-runner

ActiveCastor-project

theod02/castor-docker-runner
============================

A docker runner for Castor (This will be used to run Castor in a docker container or run the same commands when running inside a container)

03[1 PRs](https://github.com/TheoD02/castor-docker-runner/pulls)PHP

Since Jun 6Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/TheoD02/castor-docker-runner)[ Packagist](https://packagist.org/packages/theod02/castor-docker-runner)[ RSS](/packages/theod02-castor-docker-runner/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Castor Docker Runner Library
============================

[](#castor-docker-runner-library)

The `castor-docker-runner` is a PHP library designed to facilitate the execution of commands, particularly within Docker containers. This library is usable with the Castor project.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [RunnerTrait](#runnertrait)
    - [DockerRunnerTrait](#dockerrunnertrait)
- [API Reference](#api-reference)
- [Contribution](#contribution)
- [License](#license)

Installation
------------

[](#installation)

To install the library, use Composer with the following command:

```
castor composer require castor/castor-docker-runner
```

Usage
-----

[](#usage)

### RunnerTrait

[](#runnertrait)

The `RunnerTrait` provides methods to execute commands. It acts as a builder for running commands. Here's an example of how to use it:

```
use Castor\Runner\RunnerTrait;

class MyRunner
{
    use RunnerTrait;

    public function getBaseCommand()
    {
        return 'composer'
    }
}

$runner = new MyRunner();
$runner->add('install')->run(); // Run the command "composer install"
```

### DockerRunnerTrait

[](#dockerrunnertrait)

The `DockerRunnerTrait` provides methods to execute commands within a Docker container. It adds methods to build the command with Docker options. Here's an example of how to use it:

```
use Castor\Runner\DockerRunnerTrait;

class SymfonyRunner
{
    use RunnerTrait {
        RunnerTrait::__construct as private __runnerTraitConstruct;
        RunnerTrait::runCommand as private __runCommand;
    }
    use DockerRunnerTrait;

    public function __construct(?Context $castorContext = null)
    {
        $this->__runnerTraitConstruct($castorContext);
    }

    protected function getBaseCommand(): array
    {
        return ['php', 'bin/console'];
    }

    public function getContainerDefinition(): ContainerDefinition
    {
        return new ContainerDefinition(
            composeName: 'my-container-compose-name',
            name: 'my-container-name',
            workingDirectory: '/app',
            user: 'www-data',
            envs: [],
        );
    }
}

$sfRunner = new SymfonyRunner();

$sfRunner
    ->add('cache:clear')
    ->add('--env', 'prod')
    ->run(); // Run the command "docker-compose exec -T my-container-compose-name php bin/console cache:clear --env=prod"
```

The `DockerRunnerTrait` provides a significant advantage when running scripts in different environments. It allows you to execute commands within a Docker container, and it intelligently determines whether the script is being run from the host or from within a Docker container.

When the script is run from the host, the command is executed in the Docker container using `docker exec`. For example, if you run the script from the host, it will execute the following command:

```
docker exec -it --workdir /app --user www-data my-container-name php bin/console cache:clear --env=prod
```

However, if the script is run from within a Docker container, the command is executed directly in the container without the need for `docker exec`. In this case, the following command will be executed:

```
php bin/console cache:clear --env=prod
```

This feature simplifies the command execution process and makes your code cleaner and more maintainable. Without this library, you would have to manually check if the script is running inside a Docker container and then construct the command accordingly, as shown in the following example:

```
$runningInDocker = file_exists('/.dockerenv');

if ($runningInDocker) {
    $command = ['php', 'bin/console', 'cache:clear', '--env=prod'];
} else {
    $command = ['docker', 'exec', '-it', '--workdir', '/app', '--user', 'www-data', 'my-container-name', 'php', 'bin/console', 'cache:clear', '--env=prod'];
}

run($command);
```

With the `DockerRunnerTrait`, this process is abstracted away, allowing you to focus on the logic of your application rather than the specifics of command execution.

API Reference
-------------

[](#api-reference)

- `RunnerTrait`: This trait provides methods to execute commands.
- `DockerRunnerTrait`: This trait provides methods to execute commands within a Docker container.
- `DockerRunner`: This class uses the `RunnerTrait` to execute Docker commands.
- `DockerUtils`: This class provides utility methods for Docker, such as checking if the current environment is inside a Docker container, checking if certain Docker containers are running, checking if a Docker image exists, and checking if a Docker network exists.

Contribution
------------

[](#contribution)

If you'd like to contribute to this project, please feel free to fork the repository, make your changes, and submit a pull request.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance40

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity20

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/010f50739c2371f0bbe9eb992f13e23f77cecf34c60fc76e7803fdf9c83ff0ab?d=identicon)[TheoD02](/maintainers/TheoD02)

---

Top Contributors

[![TheoD02](https://avatars.githubusercontent.com/u/72203064?v=4)](https://github.com/TheoD02 "TheoD02 (3 commits)")

### Embed Badge

![Health badge](/badges/theod02-castor-docker-runner/health.svg)

```
[![Health](https://phpackages.com/badges/theod02-castor-docker-runner/health.svg)](https://phpackages.com/packages/theod02-castor-docker-runner)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
