php artisan migrate에서 SQLSTATE [HY000] [2002] 오류가 발생합니다.
소개
한 번 컨테이너 등을 down 한 후 다시 up하여 migrate
하려고하면 오류가 발생하여 해결한 방법을 메모합니다.
한가지 해결책이므로 참고가 되면 다행입니다.
조건
mac OS "11.2.3 Big Sur"
Laravel Framework "6.20.27"
PHP "8.0.7"
nginx "1.18"
mysql "8.0"
php artisan migrate를 더 이상 사용할 수 없습니다.
❶ docker-compose down
Stopping web_1 ... done
Stopping app_1 ... done
Stopping db_1 ... done
Removing web_1 ... done
Removing app_1 ... done
Removing db_1 ... done
Removing network lantern_default
❷ docker-compose up -d
Creating app_1 ... done
Creating db_1 ... done
Creating web_1 ... done
① 한 번 up한 コンテナ
ネットワーク
ボリューム
イメージ
를 삭제합니다.
기본적으로 컨테이너와 네트워크만 삭제합니다.
② 이미지를 작성, 한층 더 컨테이너를 작성·기동한다.
지금까지 제대로 된 것처럼 보이지만 app 컨테이너 내에서 migrate
를 시도하면 다음 오류가 발생합니다.
% docker-compose exec app bash
/var/www/html# php artisan migrate
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from information_schema.tables where table_schema = lantern and table_name = migrations and table_type = 'BASE TABLE')
at /var/www/html/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/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=db;port=3306;dbname=lantern", "lantern_user", "lantern_pass", [])
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
Please use the argument -v to see more details.
실제 터미널 화면
다음 오류는 DB_HOST
가 다른 경우 표시됩니다.
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
이것은, .env
로 설정하고 있는 DB_HOST
의 값과, docker-compose.yml
.envDB_HOST=db
docker-compose.ymlservices:
app:
build:
context: .
dockerfile: ./docker/php/Dockerfile
( 省略 )
web:
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
( 省略 )
db: # servicesで設定しているDB名
build:
context: .
dockerfile: ./docker/mysql/Dockerfile
( 省略 )
그러나 이름이 일치하기 때문에 이것이 원인이 아니라는 것을 알 수 있습니다.
services
에서 컨테이너의 모습을 본다. (db 떨어지고 있다···.)
% docker-compose ps
Name Command State Ports
------------------------------------------------------------------------------------------
db docker-entrypoint.sh mysqld Exit 1
app_1 docker-php-entrypoint php-fpm Up 9000/tcp
web_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:80->80/tcp,:::80->80/tcp
docker-compose ps
를 보지만, log
표기는 보이지 않는다.
% docker-compose logs
(dbのlogのみ表示)
db | 2021-08-25 13:50:26+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started.
db | 2021-08-25 13:50:27+09:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db | 2021-08-25 13:50:27+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started.
만약을 위해, app 컨테이너내에서 캐시를 미리 삭제해도 변화 없음.
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
해결
[Error]
를 일괄 삭제하여 해결되었습니다.
% docker volume prune
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Deleted Volumes:
ba53e7ce7cfad60548a239ec1164eaffa33b25c0f3ab6704f4c04fe98c4ed362
673fcb4811cf0029496745d2231d3c2a35ce1ee2257c23b1bb5ae3f74de02f6b
75d6dc4cd93203db7002431d2f39e3135cec328afe3222535366b2b1a6064d11
7804e118e3461ffa02cef0eea6a2f9850990f4b48e9c5b61e1a82c50c684357a
docker-laravel-env_db-store
c7f73c4d0fa34e29c75e41bd6f2e5f0d568ee348b3252d003eeadb04086d7d30
6a9a9caed760fad54e01bb66ae73e1dbbd48afe77ff2ddee1c85abc3426193da
b0e76adbcee655df609bd5ef13532d8ffb3ad64b5e5efff608aec40092355a64
5797c61813c2913ef44b9d90dd6b1cca53bc850b90aed2461d7bccaceb8e9de9
d2f7fbc5ff229dc742889062e78ed15b915ec239598ce8d004cdcb43bc6955e6
fe16849776b7f034a9a69231b9544e73afeb8e1a63fac803a439c1dd0385dc37
e08385c1d6a81c0b358511400ec183b1522956aff0516e670d9f88ad69d5c58e
5ab426718d1c9cf03ca17178637f78bcbedb0341be24361cb0689272f73b0a7b
lantern_mysql-volume
b307a1d46318a7e31248ba195de7b164b6db6f805684b7aaca81fac9cafb3112
e6678666f6b728cd69e2f4cc60ba8f01b2adf70e203625b4c6d8418e0a2f4362
6a0685551380139c2947862b799881ccc75c85f28679b3bf632474a0349c0ed4
ee2157d4d73bc7d7eac844350b58517aa7a64eab30138f9c8b201e93cb176ea1
69f2fef782f831b84162ac586f9379b7f82bde17a7c2d9686139bfdbd6b94108
647296d44ca8e9fa9ee7709ec5f26133dc3073da77cc2f3c46e83684afac87c5
Total reclaimed space: 2.817GB
꽤 쌓인 것 같습니다.
docker로 에러가 되었을 때의 대처법을 또 하나 알 수 있었습니다.
참고
Reference
이 문제에 관하여(php artisan migrate에서 SQLSTATE [HY000] [2002] 오류가 발생합니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/greencha/items/9acf33959ea310fdbae1
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
mac OS "11.2.3 Big Sur"
Laravel Framework "6.20.27"
PHP "8.0.7"
nginx "1.18"
mysql "8.0"
php artisan migrate를 더 이상 사용할 수 없습니다.
❶ docker-compose down
Stopping web_1 ... done
Stopping app_1 ... done
Stopping db_1 ... done
Removing web_1 ... done
Removing app_1 ... done
Removing db_1 ... done
Removing network lantern_default
❷ docker-compose up -d
Creating app_1 ... done
Creating db_1 ... done
Creating web_1 ... done
① 한 번 up한 コンテナ
ネットワーク
ボリューム
イメージ
를 삭제합니다.
기본적으로 컨테이너와 네트워크만 삭제합니다.
② 이미지를 작성, 한층 더 컨테이너를 작성·기동한다.
지금까지 제대로 된 것처럼 보이지만 app 컨테이너 내에서 migrate
를 시도하면 다음 오류가 발생합니다.
% docker-compose exec app bash
/var/www/html# php artisan migrate
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from information_schema.tables where table_schema = lantern and table_name = migrations and table_type = 'BASE TABLE')
at /var/www/html/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/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=db;port=3306;dbname=lantern", "lantern_user", "lantern_pass", [])
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
Please use the argument -v to see more details.
실제 터미널 화면
다음 오류는 DB_HOST
가 다른 경우 표시됩니다.
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
이것은, .env
로 설정하고 있는 DB_HOST
의 값과, docker-compose.yml
.envDB_HOST=db
docker-compose.ymlservices:
app:
build:
context: .
dockerfile: ./docker/php/Dockerfile
( 省略 )
web:
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
( 省略 )
db: # servicesで設定しているDB名
build:
context: .
dockerfile: ./docker/mysql/Dockerfile
( 省略 )
그러나 이름이 일치하기 때문에 이것이 원인이 아니라는 것을 알 수 있습니다.
services
에서 컨테이너의 모습을 본다. (db 떨어지고 있다···.)
% docker-compose ps
Name Command State Ports
------------------------------------------------------------------------------------------
db docker-entrypoint.sh mysqld Exit 1
app_1 docker-php-entrypoint php-fpm Up 9000/tcp
web_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:80->80/tcp,:::80->80/tcp
docker-compose ps
를 보지만, log
표기는 보이지 않는다.
% docker-compose logs
(dbのlogのみ表示)
db | 2021-08-25 13:50:26+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started.
db | 2021-08-25 13:50:27+09:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db | 2021-08-25 13:50:27+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started.
만약을 위해, app 컨테이너내에서 캐시를 미리 삭제해도 변화 없음.
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
해결
[Error]
를 일괄 삭제하여 해결되었습니다.
% docker volume prune
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Deleted Volumes:
ba53e7ce7cfad60548a239ec1164eaffa33b25c0f3ab6704f4c04fe98c4ed362
673fcb4811cf0029496745d2231d3c2a35ce1ee2257c23b1bb5ae3f74de02f6b
75d6dc4cd93203db7002431d2f39e3135cec328afe3222535366b2b1a6064d11
7804e118e3461ffa02cef0eea6a2f9850990f4b48e9c5b61e1a82c50c684357a
docker-laravel-env_db-store
c7f73c4d0fa34e29c75e41bd6f2e5f0d568ee348b3252d003eeadb04086d7d30
6a9a9caed760fad54e01bb66ae73e1dbbd48afe77ff2ddee1c85abc3426193da
b0e76adbcee655df609bd5ef13532d8ffb3ad64b5e5efff608aec40092355a64
5797c61813c2913ef44b9d90dd6b1cca53bc850b90aed2461d7bccaceb8e9de9
d2f7fbc5ff229dc742889062e78ed15b915ec239598ce8d004cdcb43bc6955e6
fe16849776b7f034a9a69231b9544e73afeb8e1a63fac803a439c1dd0385dc37
e08385c1d6a81c0b358511400ec183b1522956aff0516e670d9f88ad69d5c58e
5ab426718d1c9cf03ca17178637f78bcbedb0341be24361cb0689272f73b0a7b
lantern_mysql-volume
b307a1d46318a7e31248ba195de7b164b6db6f805684b7aaca81fac9cafb3112
e6678666f6b728cd69e2f4cc60ba8f01b2adf70e203625b4c6d8418e0a2f4362
6a0685551380139c2947862b799881ccc75c85f28679b3bf632474a0349c0ed4
ee2157d4d73bc7d7eac844350b58517aa7a64eab30138f9c8b201e93cb176ea1
69f2fef782f831b84162ac586f9379b7f82bde17a7c2d9686139bfdbd6b94108
647296d44ca8e9fa9ee7709ec5f26133dc3073da77cc2f3c46e83684afac87c5
Total reclaimed space: 2.817GB
꽤 쌓인 것 같습니다.
docker로 에러가 되었을 때의 대처법을 또 하나 알 수 있었습니다.
참고
Reference
이 문제에 관하여(php artisan migrate에서 SQLSTATE [HY000] [2002] 오류가 발생합니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/greencha/items/9acf33959ea310fdbae1
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
❶ docker-compose down
Stopping web_1 ... done
Stopping app_1 ... done
Stopping db_1 ... done
Removing web_1 ... done
Removing app_1 ... done
Removing db_1 ... done
Removing network lantern_default
❷ docker-compose up -d
Creating app_1 ... done
Creating db_1 ... done
Creating web_1 ... done
% docker-compose exec app bash
/var/www/html# php artisan migrate
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from information_schema.tables where table_schema = lantern and table_name = migrations and table_type = 'BASE TABLE')
at /var/www/html/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/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=db;port=3306;dbname=lantern", "lantern_user", "lantern_pass", [])
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
Please use the argument -v to see more details.
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
DB_HOST=db
services:
app:
build:
context: .
dockerfile: ./docker/php/Dockerfile
( 省略 )
web:
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
( 省略 )
db: # servicesで設定しているDB名
build:
context: .
dockerfile: ./docker/mysql/Dockerfile
( 省略 )
% docker-compose ps
Name Command State Ports
------------------------------------------------------------------------------------------
db docker-entrypoint.sh mysqld Exit 1
app_1 docker-php-entrypoint php-fpm Up 9000/tcp
web_1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:80->80/tcp,:::80->80/tcp
% docker-compose logs
(dbのlogのみ表示)
db | 2021-08-25 13:50:26+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started.
db | 2021-08-25 13:50:27+09:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db | 2021-08-25 13:50:27+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started.
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
[Error]
를 일괄 삭제하여 해결되었습니다.% docker volume prune
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Deleted Volumes:
ba53e7ce7cfad60548a239ec1164eaffa33b25c0f3ab6704f4c04fe98c4ed362
673fcb4811cf0029496745d2231d3c2a35ce1ee2257c23b1bb5ae3f74de02f6b
75d6dc4cd93203db7002431d2f39e3135cec328afe3222535366b2b1a6064d11
7804e118e3461ffa02cef0eea6a2f9850990f4b48e9c5b61e1a82c50c684357a
docker-laravel-env_db-store
c7f73c4d0fa34e29c75e41bd6f2e5f0d568ee348b3252d003eeadb04086d7d30
6a9a9caed760fad54e01bb66ae73e1dbbd48afe77ff2ddee1c85abc3426193da
b0e76adbcee655df609bd5ef13532d8ffb3ad64b5e5efff608aec40092355a64
5797c61813c2913ef44b9d90dd6b1cca53bc850b90aed2461d7bccaceb8e9de9
d2f7fbc5ff229dc742889062e78ed15b915ec239598ce8d004cdcb43bc6955e6
fe16849776b7f034a9a69231b9544e73afeb8e1a63fac803a439c1dd0385dc37
e08385c1d6a81c0b358511400ec183b1522956aff0516e670d9f88ad69d5c58e
5ab426718d1c9cf03ca17178637f78bcbedb0341be24361cb0689272f73b0a7b
lantern_mysql-volume
b307a1d46318a7e31248ba195de7b164b6db6f805684b7aaca81fac9cafb3112
e6678666f6b728cd69e2f4cc60ba8f01b2adf70e203625b4c6d8418e0a2f4362
6a0685551380139c2947862b799881ccc75c85f28679b3bf632474a0349c0ed4
ee2157d4d73bc7d7eac844350b58517aa7a64eab30138f9c8b201e93cb176ea1
69f2fef782f831b84162ac586f9379b7f82bde17a7c2d9686139bfdbd6b94108
647296d44ca8e9fa9ee7709ec5f26133dc3073da77cc2f3c46e83684afac87c5
Total reclaimed space: 2.817GB
꽤 쌓인 것 같습니다.
docker로 에러가 되었을 때의 대처법을 또 하나 알 수 있었습니다.
참고
Reference
이 문제에 관하여(php artisan migrate에서 SQLSTATE [HY000] [2002] 오류가 발생합니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/greencha/items/9acf33959ea310fdbae1
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(php artisan migrate에서 SQLSTATE [HY000] [2002] 오류가 발생합니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/greencha/items/9acf33959ea310fdbae1텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)