Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

arturd's avatar

artisan migrate error with docker, laravel sail and postgresql

I am installing laravel sail with jetstream and postgresql. The installation is ok and the laravel container can see the postgresql one. I am showing data from the db in the controller. Until there everything ok. But when I try to install jetstream and do the table migration, it returns:

php artisan migrate:

could not translate host name "mycontainer" to address

    'pgsql' => [
        'driver' => 'pgsql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', 'mypgcontainer'),
        'port' => env('DB_PORT', '5432'),
        'database' => env('DB_DATABASE', 'mydb'),
        'username' => env('DB_USERNAME', 'myuser'),
        'password' => env('DB_PASSWORD', 'mypass'),
        'charset' => 'utf8',
        'prefix' => '',
        'prefix_indexes' => true,
        'schema' => 'public',
        'sslmode' => 'prefer',
    ],

It also doesn't work with DB_HOST 127.0.0.1 or localhost, because in that case laravel no longer connects with postgresql

SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "127.0.0.1"

The strange thing is that I can successfully connect from laravel to postgre and display data on screen with db_host 'mypgcontainer', but the migration with artisan return error

Any idea? Thanks!!

0 likes
6 replies
arturd's avatar

it doesn't work, in fact no sail command works. This did work for me:

docker exec mycontainer php artisan migrate

Brandon Eichhorn's avatar

@arturd If that doesn't work, use ./vendor/bin/sail

sail only works if you've made an alias for it. :)

2 likes
arturd's avatar

I have an alias working:

sail --version
docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

but when I run the command in a fresh sail installation:

sail composer require laravel/jetstream

it doesn't return anything, no answer, just drop a line and nothing else.

I've been trying to build a docker for 3 days, with sail and postgresql and I still can't implement it quickly, this should be able to install in just a few minutes...

Cryborg's avatar

@arturd I know this is an old thread, but I had the same problem, sail commands didn't return anything. It was because I changed the default "laravel.test" in docker-compose.yml services, and I hadn't set the APP_SERVICE variable accordingly in my .env.

arturd's avatar

@Cryborg I had several problems with sail to do clean installations, I think I'll go for doing the classic installation

Please or to participate in this conversation.