2

I created a new Laravel project and installed Sail with composer require laravel/sail --dev followed by php artisan sail:install and sail up to get the project up and running in Docker.

By doing these actions my .env file changed from

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_docker
DB_USERNAME=root
DB_PASSWORD=

to

DB_CONNECTION=pgsql
DB_HOST=pgsql
DB_PORT=5432
DB_DATABASE=laravel_docker
DB_USERNAME=sail
DB_PASSWORD=password

And now I got two running Docker containers:

laravel-docker_laravel.test_1
laravel-docker_pgsql_1

I'm able to run the basic user migration with sail artisan migrate.

Next up I want to connect Tableplus (or Postico) with my Postgresql database running in Docker. Therefore I filled in the following information:

Tableplus screenshot

When trying to connect I got ERROR FATAL: role "sail" does not exist.

Can someone help me out?

Edit 1: Adding a screenshot from some terminal commands. I can connect to the database in the docker container, see a list of the tables and get a table with all the rows from the users table (inserted with a seeder using Laravel Sail)

CLI screenshot

Edit 2: docker-compose ps

docker-compose up screenshot

Thore
  • 1,918
  • 2
  • 25
  • 50
  • What you get changing the host/socket from localhost to pgsql? – porloscerros Ψ Jun 06 '21 at 17:32
  • @porloscerrosΨ Error message 'could not translate host name "pgsql" to address: nodename nor servname provided, or not known' – Thore Jun 06 '21 at 17:43
  • just to discard ... does the .env file setup works? that is, laravel can connect to the db? – porloscerros Ψ Jun 06 '21 at 17:53
  • The docker containers are running and I was able to migrate the basic user table with sail artisan migrate so I assume it works. I can do an extra check. Give me a minute to write some code to store a user – Thore Jun 06 '21 at 17:58
  • 1
    @porloscerrosΨ Yes, I'm able to run a seeder and create users – Thore Jun 06 '21 at 18:08
  • @porloscerrosΨ Added a screenshot of my terminal – Thore Jun 06 '21 at 18:38
  • Can you show us what `docker-compose ps` looks like ? Also, this should not change anything but instead of using `localhost` try `127.0.0.1` – matiaslauriti Jun 06 '21 at 19:08
  • @matiaslauriti Changing localhost tot 127.0.0.1 gives the same result ~ FATAL: role "sail" does not exist. I've added a screenshot with the result of `docker-compose ps`, see Edit 2. – Thore Jun 07 '21 at 00:22
  • Just for testing, try to connect to `template1` or `template0` instead of `laravel_docker` – matiaslauriti Jun 07 '21 at 00:48
  • @matiaslauriti When trying to connect to template0 I get the following error `database "template0" is not currently accepting connections`. template1 is accessible 'You are now connected to database "template1" as user "sail".' – Thore Jun 07 '21 at 06:59
  • @Thore I have no idea about Postgre but I think it is related to some permissions, as you can see on your screenshot – matiaslauriti Jun 07 '21 at 15:49

2 Answers2

3

Thanks to this post I found a working solution.

Changing to a different port in the docker-compose.yml file fixed the issue.

Before:

pgsql:
    image: 'postgres:13'
    ports:
        - '${FORWARD_DB_PORT:-5432}:5432'

After:

pgsql:
    image: 'postgres:13'
    ports:
        - '${FORWARD_DB_PORT:-5632}:5432'

After changing the port number to 5632 in TablePlus I'm able to connect to the database.

Thore
  • 1,918
  • 2
  • 25
  • 50
0

I have the same problem "role "sail" does not exist". In this case we need to use command ./vendor/bin/sail down -v to delete the existing Docker volume data. After that you can do ./vendor/bin/sail up command.