A story that got stuck with an error during migration in docker PHP laravel

A story about getting an error during migration in docker (laravel)

The following is the error content

terminal


SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from information_schema.tables where table_schema = db_name and table_name = migrations and table_type = 'BASE TABLE')

  at /var/www/html/laravel-vue-app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
    665|         // If an exception occurs when attempting to run a query, we'll format the error
    666|         // message to include the bindings with SQL, which will make this exception a
    667|         // lot more helpful to the developer instead of just the database's errors.
    668|         catch (Exception $e) {
  > 669|             throw new QueryException(
    670|                 $query, $this->prepareBindings($bindings), $e
    671|             );
    672|         }
    673|

  Exception trace:

  1   PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known")
      /var/www/html/laravel-vue-app/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  2   PDO::__construct("mysql:host=mysql;port=3306;dbname=db_name", "db_user", "db_password", [])
      /var/www/html/laravel-vue-app/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  Please use the argument -v to see more details.

In conclusion, docker-compose.yml and .env mysql settings must be the same

solution

Check if .env under laravel (app /) exists-> Host name must be matched with docker container name Need to change if there is a difference in the contents of docker-compose.yml After the change

docker


docker-compose stop
docker-compose up -d

It is necessary to do Reason: restart doesn't reflect the docker-compose.yml settings If you want to reflect the setting of .env

terminal


php artisan config:cache

Need to be reflected in

Cause (additional note)

Apparently the app container where laravel is billed-> the db container where mysql is built It seems that an error has occurred when communicating with each other, When communicating between docker containers, enter the IP address given to the container in which mysql is built. It is necessary to use

terminal


cat /etc/hosts | awk ‘END{print $1}’ | sed -r -e ‘s/[0-9]+$/1/g’

You can check the IP address of the container with You should check if the host IP of .env under app is the same.

Recommended Posts

A story that got stuck with an error during migration in docker PHP laravel
[Docker] The story that an error occurred in docker-compose up
I got a Permission Denied error when I put Laravel in Docker
A story stuck with log output in Docker + Play framework environment
When I bcrypt with node + docker, I got an error
A story about an error collating checksum values after npm install with Laravel Homestead
A story stuck with NotSerializableException
A story stuck with an error when building Vagrant + Virtulbox CentOS7.8 and creating a shared folder
A solution to Docker errors that beginners tend to get stuck in
General error: 1812 occurs with docker + laravel
The story that Tomcat suffered from a timeout error in Eclipse
A story that addresses the problem that REMOTE_ADDR cannot be acquired in a cluster built with Docker Swarm + Traefik (1.7).
Command line that can create a directory structure for building a Laravel environment with Docker in one shot
When I tried to build an environment of PHP7.4 + Apache + MySQL with Docker, I got stuck [Windows & Mac]
A story about an arithmetic overflow that you shouldn't encounter in Ruby
When introducing JOOQ to Spring boot, a story that was dealt with because an error occurred around Liquibase
A story about saving an image with carrierwave in a nested form using a form object.
[Part 1] Creating a Docker container that delivers Markdown in HTML with Apache / Pandoc
Stuck in an enum in front of a blacksmith
Just install Laravel8 on docker in PHP8 environment
The story that docker had a hard time
Webdrivers :: BrowserNotFound: Failed to find Chrome binary. When I was trying to test E2E with Docker + Rails for the first time, I got stuck in an error.
Migration error after Activerecord association in Rails5 + Docker environment (2)
[PHP] A story about outputting PDF with TCPDF + FPDI
A simple CRUD app made with Nuxt / Laravel (Docker)
One case of solving a migration error in Rails
A small story that is sometimes useful in Maven
Build Docker + Laravel PHP + Vue.js development environment in 5 minutes
Migration error after Activerecord association in Rails5 + Docker environment
Verification value error that occurred in a clustering environment
[Note] Build a Python3 environment with Docker in EC2
I got an error "undefined method` create'" in RSpec
Quickly implement a singleton with an enum in Java
I got stuck in a clone of a two-dimensional array
When trying to insert a specific gem (levenshtein) with Docker, an error occurred without ruby-dev
(For myself) Build an IDE that you can touch from a browser with docker (trial)
A story that I realized that I had to study as an engineer in the first place