testcontainers / testcontainers-php

https://www.testcontainers.org implementation for PHP
MIT License
91 stars 16 forks source link

Exit Code: 125(Unknown error) docker: invalid reference format. Laravel #18

Closed raviMukti closed 3 weeks ago

raviMukti commented 3 weeks ago

I had some problem with PostgresContainer, its just cannot run the container and always throwing error

here is my implementation

<?php

namespace Tests\Feature\Auth;

use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Testcontainers\Container\PostgresContainer;
use Tests\TestCase;

class AuthenticationTest extends TestCase
{
    use RefreshDatabase;

    /** @var PostgresContainer $postgresContainer */
    protected static $postgresContainer;

    public function setUp(): void
    {
        // Setup PostgresContainer
        self::$postgresContainer = PostgresContainer::make('postgres:14-alpine');
        self::$postgresContainer->withPostgresDatabase('test');
        self::$postgresContainer->withPostgresUser('test');
        self::$postgresContainer->run();

        parent::setUp();
    }

    public function tearDown(): void
    {
        // Tear down PostgresContainer
        self::$postgresContainer->stop();
        self::$postgresContainer->remove();

        parent::tearDown();
    }

    // assert user can login
    public function test_user_can_login()
    {
        $user = User::factory()->create();

        $response = $this->post('/login', [
            'email' => $user->email,
            'password' => 'password',
        ]);

        $response->assertSessionHasNoErrors();
    }
}

the errors

 The command "'docker' 'run' '--rm' '--detach' '--name' 'testcontainer66fdd8c06cbdf9.16498986' '--env' 'POSTGRES_PASSWORD=root' '--env' 'POSTGRES_DB=test' '--env' 'POSTGRES_USER=test' 'postgres:postgres:14-alpine'" failed.

Exit Code: 125(Unknown error)

Working directory: blabla

Output:
================

Error Output:
================
docker: invalid reference format.
See 'docker run --help'.

any helps would be appreciate

raviMukti commented 3 weeks ago

Oops my bad, it's because the image version invalid, should be remove the postgres and simple just like this

self::$postgresContainer = PostgresContainer::make('14-alpine');