Skip to content

Commit fcb20e6

Browse files
committed
Support user-specific and privileged exec
1 parent a7a0d7c commit fcb20e6

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

src/Client.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -904,16 +904,18 @@ public function imageSearch($term)
904904
* STDOUT/STDERR are multiplexed into separate streams + relatively slow
905905
* This looks strange to you? It probably is. Consider using the first option instead.
906906
*
907-
* @param string $container container ID
908-
* @param string|array $cmd Command to run specified as an array of strings or a single command string
909-
* @param boolean $tty TTY mode
910-
* @param boolean $stdin attaches to STDIN of the exec command
911-
* @param boolean $stdout attaches to STDOUT of the exec command
912-
* @param boolean $stderr attaches to STDERR of the exec command
907+
* @param string $container container ID
908+
* @param string|array $cmd Command to run specified as an array of strings or a single command string
909+
* @param boolean $tty TTY mode
910+
* @param boolean $stdin attaches to STDIN of the exec command
911+
* @param boolean $stdout attaches to STDOUT of the exec command
912+
* @param boolean $stderr attaches to STDERR of the exec command
913+
* @param string|int $user user-specific exec, otherwise defaults to main container user (requires API v1.19+ / Docker v1.7+)
914+
* @param boolean $privileged privileged exec with all capabilities enabled (requires API v1.19+ / Docker v1.7+)
913915
* @return PromiseInterface Promise<array> with exec ID in the form of `array("Id" => $execId)`
914916
* @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#exec-create
915917
*/
916-
public function execCreate($container, $cmd, $tty = false, $stdin = false, $stdout = true, $stderr = true)
918+
public function execCreate($container, $cmd, $tty = false, $stdin = false, $stdout = true, $stderr = true, $user = '', $privileged = false)
917919
{
918920
if (!is_array($cmd)) {
919921
$cmd = array('sh', '-c', (string)$cmd);
@@ -932,6 +934,8 @@ public function execCreate($container, $cmd, $tty = false, $stdin = false, $stdo
932934
'AttachStdin' => !!$stdin,
933935
'AttachStdout' => !!$stdout,
934936
'AttachStderr' => !!$stderr,
937+
'User' => $user,
938+
'Privileged' => !!$privileged,
935939
)
936940
)->then(array($this->parser, 'expectJson'));
937941
}

tests/FunctionalClientTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,24 @@ public function testExecStringCommandWithOutputWhileRunning($container)
171171
$this->assertEquals('hello world', $output);
172172
}
173173

174+
/**
175+
* @depends testStartRunning
176+
* @param string $container
177+
*/
178+
public function testExecUserSpecificCommandWithOutputWhileRunning($container)
179+
{
180+
$promise = $this->client->execCreate($container, 'whoami', true, false, true, true, 'nobody');
181+
$exec = Block\await($promise, $this->loop);
182+
183+
$this->assertTrue(is_array($exec));
184+
$this->assertTrue(is_string($exec['Id']));
185+
186+
$promise = $this->client->execStart($exec['Id'], true);
187+
$output = Block\await($promise, $this->loop);
188+
189+
$this->assertEquals('nobody', rtrim($output));
190+
}
191+
174192
/**
175193
* @depends testStartRunning
176194
* @param string $container

0 commit comments

Comments
 (0)