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

mauricioguim's avatar

Error Connecting Laravel Sail Application to MySQL Database

In a Laravel (Version 11) application using Sail, I am unable to connect to the MySQL database.

The project was created using the following command:

curl -s "https://laravel.build/example-app?with=mysql" | bash

The containers were created correctly.

However, the only changes made before starting the application were renaming the container names.

By default, Laravel created the containers with the following names:

  • example-app-laravel.test-1 (for app container)
  • example-app-mysql-1 (for MySQL container)

In the docker-compose.yml file, I added the container_name attribute to rename the container names. That is, for the app container:

services:  
  laravel.test:  
    container_name: example-app  

For the MySQL container:

mysql:
  container_name: example-database

However, after this change, the application could no longer connect to the database.

What is wrong? What needs to be done to rename the container names without causing errors?

1 like
2 replies

Please or to participate in this conversation.