/** * Pulls an image from the Docker registry, then inspects the image * to make sure it has been properly created. */ public function testPullImage() { $remote = new DockerRemoteRequest(); // Create a new image. ubuntu:15.10. $remote->Post(['uri' => '/images/create?fromImage=ubuntu&tag=15.10', 'accept' => 'application/json']); // Inspect the image to make sure it has been created. $this->assertNotEmpty($remote->Get(['uri' => '/images/ubuntu:15.10/json', 'accept' => 'application/json'])); }
/** * Execute a command in a container. */ public function testExecuteCommand() { $remote = new DockerRemoteRequest(); // Create a new container. $container = $remote->Post(['uri' => '/containers/create?name=exec_container_test', 'content_type' => 'application/json', 'accept' => 'application/json', 'content' => ['Image' => 'ubuntu:15.10', 'Cmd' => ['/bin/bash']]]); // Start the container. $remote->Post(['uri' => '/containers/exec_container_test/start']); // Check the container is running. $inspect = $remote->Get(['uri' => '/containers/exec_container_test/json', 'accept' => 'application/json']); $this->assertTrue($inspect->State->Running); // Set up a exec instance on the container. $exec_id = $remote->Post(['uri' => '/containers/exec_container_test/exec', 'content_type' => 'application/json', 'accept' => 'application/json', 'content' => ['AttachStdin' => FALSE, 'AttachStdout' => TRUE, 'AttachStdErr' => TRUE, 'Tty' => FALSE, 'Cmd' => ['bash', '-c', 'echo "test"']]]); $this->assertNotEmpty($exec_id->Id); // Check the container is running. $inspect = $remote->Get(['uri' => '/containers/exec_container_test/json', 'accept' => 'application/json']); $this->assertTrue($inspect->State->Running); // Exec the exec instance. $result = $remote->Post(['uri' => '/exec/' . $exec_id->Id . '/start', 'content_type' => 'application/json', 'accept' => 'application/json', 'content' => ['Detach' => FALSE, 'Tty' => FALSE]]); }