File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed
Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff 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
8797You can name the container by passing the name as the second argument to the constructor.
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+
177185it ('can generate copy command ' , function () {
178186 $ command = $ this ->container
179187 ->getCopyCommand ('abcdefghijkl ' , '/home/spatie ' , '/mnt/spatie ' );
You can’t perform that action at this time.
0 commit comments