Skip to content

Commit a33d71b

Browse files
authored
Merge pull request #56 from dimitri-koenig/feature/custom-docker-bin
add custom docker bin option
2 parents 858ced6 + a7b75cb commit a33d71b

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ $containerInstance = DockerContainer::create($imageName)
8282
->start();
8383
```
8484

85+
#### Custom docker binary
86+
87+
If the `docker` binary is not globally available, you can specify the exact path.
88+
89+
```php
90+
$containerInstance = DockerContainer::create($imageName)
91+
->dockerBin('/usr/local/bin/docker')
92+
->start();
93+
```
94+
8595
#### Naming the container
8696

8797
You can name the container by passing the name as the second argument to the constructor.

src/DockerContainer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class DockerContainer
1818

1919
public bool $privileged = false;
2020

21+
public string $dockerBin = 'docker';
22+
2123
public string $shell = 'bash';
2224

2325
public ?string $network = null;
@@ -88,6 +90,13 @@ public function privileged(bool $privileged = true): self
8890
return $this;
8991
}
9092

93+
public function dockerBin(string $dockerBin): self
94+
{
95+
$this->dockerBin = $dockerBin;
96+
97+
return $this;
98+
}
99+
91100
public function shell(string $shell): self
92101
{
93102
$this->shell = $shell;
@@ -192,7 +201,7 @@ public function command(string $command): self
192201
public function getBaseCommand(): string
193202
{
194203
$baseCommand = [
195-
'docker',
204+
$this->dockerBin,
196205
...$this->getExtraDockerOptions(),
197206
];
198207

tests/DockerContainerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@
174174
expect($command)->toEqual('echo "whoami" | docker exec --interactive abcdefghijkl sh -');
175175
});
176176

177+
it('can generate exec command with custom docker bin', function () {
178+
$command = $this->container
179+
->dockerBin('/usr/local/bin/docker')
180+
->getExecCommand('abcdefghijkl', 'whoami');
181+
182+
expect($command)->toEqual('echo "whoami" | /usr/local/bin/docker exec --interactive abcdefghijkl bash -');
183+
});
184+
177185
it('can generate copy command', function () {
178186
$command = $this->container
179187
->getCopyCommand('abcdefghijkl', '/home/spatie', '/mnt/spatie');

0 commit comments

Comments
 (0)