예제 #1
0
    def test_create_start_container_with_stdin_to_file(
            self, tmpdir, docker_client: ContainerClient):
        container_name = _random_container_name()
        message = "test_message_stdin"
        try:
            docker_client.create_container(
                "alpine",
                name=container_name,
                interactive=True,
                command=["sh", "-c", "cat > test_file"],
            )

            output, _ = docker_client.start_container(
                container_name,
                interactive=True,
                stdin=message.encode(config.DEFAULT_ENCODING))
            target_path = tmpdir.join("test_file")
            docker_client.copy_from_container(container_name, str(target_path),
                                              "test_file")

            assert message == target_path.read().strip()
        finally:
            docker_client.remove_container(container_name)
예제 #2
0
    def test_container_lifecycle_commands(self, docker_client: ContainerClient):
        container_name = _random_container_name()
        output = docker_client.create_container(
            "alpine",
            name=container_name,
            command=["sh", "-c", "for i in `seq 30`; do sleep 1; echo $i; done"],
        )
        container_id = output.strip()
        assert container_id

        try:
            docker_client.start_container(container_id)
            assert DockerContainerStatus.UP == docker_client.get_container_status(container_name)
            docker_client.stop_container(container_id)
            assert DockerContainerStatus.DOWN == docker_client.get_container_status(container_name)
        finally:
            docker_client.remove_container(container_id)

        assert DockerContainerStatus.NON_EXISTENT == docker_client.get_container_status(
            container_name
        )
예제 #3
0
 def test_create_container_non_existing_image(
         self, docker_client: ContainerClient):
     with pytest.raises(NoSuchImage):
         docker_client.create_container(
             "this_image_does_hopefully_not_exist_42069")