当出现 MySQL 容器永远进入正在重新启动状态的问题时,应对措施是什么?

生態的背景

    • PHP: 8.0.28

 

    • Laravel: 9.52.5

 

    MySQL: 8.0.32

出现了

$ docker compose ps
NAME           IMAGE      COMMAND                  SERVICE             CREATED             STATUS                         PORTS
db-server      mysql      "docker-entrypoint.s…"   mysql               7 minutes ago       Restarting (1) 3 seconds ago

出现了一个问题,状态始终处于“重新启动”状态,并且每60秒就会持续重新启动。

$ docker compose logs mysql
...
db-server  | 2023-03-30 18:42:37+09:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db-server  | 2023-03-30 18:42:37+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.32-1.el8 started.
db-server  | 2023-03-30 18:42:38+09:00 [Note] [Entrypoint]: Initializing database files
...

謎般地,↑的日誌持續地永遠展示著。

$ 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 = xxxxxx and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:760
    756▕         // If an exception occurs when attempting to run a query, we'll format the error
    757▕         // message to include the bindings with SQL, which will make this exception a
    758▕         // lot more helpful to the developer instead of just the database's errors.
    759▕         catch (Exception $e) {
  ➜ 760▕             throw new QueryException(
    761▕                 $query, $this->prepareBindings($bindings), $e
    762▕             );
    763▕         }
    764▕     }

      +39 vendor frames
  40  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

试着迁移时出现了找不到主机的错误。(因为MySQL容器未运行当然会出现这种情况)

嘗試過了但並未改善

使用Docker Compose停止并重新创建容器
使用Docker Compose停止并清除卷
重新启动Docker桌面
重新启动Mac电脑

重新构建Docker镜像

$ docker compose build --no-cache

 => [internal] load build context                                                                                                                      0.0s
 => => transferring context: 69B                                                                                                                       0.0s
 => ERROR [stage-0 2/8] RUN apt-get update     && apt install -y lsb-release ca-certificates apt-transport-https software-properties-common bash-comp  0.6s
------
 > [stage-0 2/8] RUN apt-get update     && apt install -y lsb-release ca-certificates apt-transport-https software-properties-common bash-completion     && apt-get install -y git unzip libzip-dev libicu-dev libonig-dev libfreetype6-dev libjpeg62-turbo-dev libpng-dev libjpeg-dev vim lsof     && docker-php-ext-install intl pdo_mysql zip bcmath:
#0 0.395 Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
#0 0.462 Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
#0 0.495 Err:1 http://deb.debian.org/debian bullseye InRelease
#0 0.495   At least one invalid signature was encountered.
#0 0.515 Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
#0 0.543 Err:2 http://deb.debian.org/debian-security bullseye-security InRelease
#0 0.543   At least one invalid signature was encountered.
#0 0.586 Err:3 http://deb.debian.org/debian bullseye-updates InRelease
#0 0.586   At least one invalid signature was encountered.
#0 0.591 Reading package lists...
#0 0.599 W: GPG error: http://deb.debian.org/debian bullseye InRelease: At least one invalid signature was encountered.
#0 0.599 E: The repository 'http://deb.debian.org/debian bullseye InRelease' is not signed.
#0 0.599 W: GPG error: http://deb.debian.org/debian-security bullseye-security InRelease: At least one invalid signature was encountered.
#0 0.599 E: The repository 'http://deb.debian.org/debian-security bullseye-security InRelease' is not signed.
#0 0.599 W: GPG error: http://deb.debian.org/debian bullseye-updates InRelease: At least one invalid signature was encountered.
#0 0.599 E: The repository 'http://deb.debian.org/debian bullseye-updates InRelease' is not signed.
------
failed to solve: executor failed running [/bin/sh -c apt-get update     && apt install -y lsb-release ca-certificates apt-transport-https software-properties-common bash-completion     && apt-get install -y git unzip libzip-dev libicu-dev libonig-dev libfreetype6-dev libjpeg62-turbo-dev libpng-dev libjpeg-dev vim lsof     && docker-php-ext-install intl pdo_mysql zip bcmath]: exit code: 100

apt-get update出问题真的太奇怪了。

我找到了一篇文章,据说如果磁盘容量满了就会出错。
链接:https://note.yu9824.com/error/2022/03/19/docker-debian-gpg-error.html

虽然没有特别的压力,但是尝试一下似乎是值得的。

解决

$ docker system prune --all
$ docker compose up -d

虽然只有大约5GB的容量,但我还是先整理了一下。

$ docker compose ps

NAME                IMAGE      COMMAND                  SERVICE             CREATED            STATUS             PORTS
db-server           mysql      "docker-entrypoint.s…"   mysql               1 minutes ago      Up 1 minutes       0.0.0.0:3306->3306/tcp, 33060/tcp

MySQL容器已经成功启动了。

$ docker compose logs mysql
db-server  | 2023-03-30 19:02:56+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.32-1.el8 started.
db-server  | 2023-03-30 19:02:56+09:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db-server  | 2023-03-30 19:02:57+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.32-1.el8 started.
db-server  | 2023-03-30 19:02:57+09:00 [Note] [Entrypoint]: Initializing database files
db-server  | 2023-03-30 19:03:02+09:00 [Note] [Entrypoint]: Database files initialized
db-server  | 2023-03-30 19:03:02+09:00 [Note] [Entrypoint]: Starting temporary server
db-server  | 2023-03-30 19:03:03+09:00 [Note] [Entrypoint]: Temporary server started.
db-server  | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
db-server  | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
db-server  | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
db-server  | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
db-server  | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
db-server  | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
db-server  | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
db-server  | 2023-03-30 19:03:06+09:00 [Note] [Entrypoint]: Creating database xxxxxx
db-server  | 2023-03-30 19:03:06+09:00 [Note] [Entrypoint]: Creating user user
db-server  | 2023-03-30 19:03:06+09:00 [Note] [Entrypoint]: Giving user user access to schema xxxxx
db-server  |
db-server  | 2023-03-30 19:03:06+09:00 [Note] [Entrypoint]: Stopping temporary server
db-server  | 2023-03-30 19:03:08+09:00 [Note] [Entrypoint]: Temporary server stopped
db-server  |
db-server  | 2023-03-30 19:03:08+09:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
db-server  |

MySQL似乎已经成功启动了。
真是令人高兴,值得庆祝。

广告
将在 10 秒后关闭
bannerAds