0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【環境構築備忘録】立ち上げようとしてもmysqlコンテナだけがexited(1)になる

Last updated at Posted at 2023-10-06

プライベートPCでのlaravelの環境構築で躓いたので、忘れないように書いておく!
docker-compose build --no-cacheがなんとかうまくいったので、docker-compose upを実行したらMySQLのコンテナがうまく立ち上がらなかった。ほかのコンテナは立ち上がるのに…。
とりあえずlogを確認してみようと思って、docker-compose logsって打ってみたら

[+] Running 3/3
 ✔ Container laravel_todo_mysql  Started
 ✔ Container laravel_todo_php    Started
 ✔ Container laravel_todo_pma    Started
PS C:\Users\EmiriYanagida\Desktop\projects\laravel_tod
laravel_todo_pma    | AH00558: apache2: Could not reliobally to suppress this message
laravel_todo_pma    | AH00558: apache2: Could not reliobally to suppress this message
laravel_todo_mysql  | 2023-08-12 10:45:20+00:00 [Note]
laravel_todo_mysql  | 2023-08-12 10:45:21+00:00 [Note]
laravel_todo_mysql  | 2023-08-12 10:45:21+00:00 [ERRORot be used for the root user
laravel_todo_pma    | [Sat Aug 12 10:45:21.630285 2023laravel_todo_pma    | [Sat Aug 12 10:45:21.630371 2023
laravel_todo_mysql  |     Remove MYSQL_USER="root" and
laravel_todo_mysql  |     - MYSQL_ROOT_PASSWORD
laravel_todo_mysql  |     - MYSQL_ALLOW_EMPTY_PASSWORD
laravel_todo_mysql  |     - MYSQL_RANDOM_ROOT_PASSWORD
laravel_todo_php    | AH00112: Warning: DocumentRoot [
laravel_todo_php    | AH00558: apache2: Could not reliobally to suppress this message
laravel_todo_php    | AH00112: Warning: DocumentRoot [
nt]: Entrypoint script for MySQL Server 8.0.34-1.el8 started.

こんなんが出てきた。よくわからない。
問題のmySQLのコンテナのログが見たかったので、docker logs laravel_todo_mysqlって打った。

2023-08-12 10:45:21+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2023-08-12 10:45:21+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.34-1.el8 started.
2023-08-12 10:45:21+00:00 [ERROR] [Entrypoint]: MYSQL_USER="root", MYSQL_USER and MYSQL_PASSWORD are for configuring a regular user and cannot be used for the roo
user and cannot be used for the root user
    Remove MYSQL_USER="root" and use one of the following to control the root user password:
    - MYSQL_ROOT_PASSWORD
    - MYSQL_ALLOW_EMPTY_PASSWORD
    - MYSQL_RANDOM_ROOT_PASSWORD

こんなんが出てきた。
エラーが出てるところの英文を見てみる。

MYSQL_USER="root", MYSQL_USER and MYSQL_PASSWORD are for configuring a regular user and cannot be used for the roo
user and cannot be used for the root user
    Remove MYSQL_USER="root" and use one of the following to control the root user password

DeepL翻訳にかけると、
「MYSQL_USER="root"、MYSQL_USER、MYSQL_PASSWORDは一般ユーザーを設定するためのものであり、ルート・ユーザーには使用できない。
MYSQL_USER="root "を削除し、以下のいずれかを使用してルート・ユーザのパスワードを制御する」
って意味らしい。docker.compose.ymlでmySQLコンテナの設定を見てみる。

mysql:
    image: mysql:8.0
    # mysql8の認証プラグイン。この記述がないと弾かれる。
    command: --default-authentication-plugin=mysql_native_password
    volumes:
      - ./docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
    ports:
        # ${DB_PORT}と.envのWEB_PORTが対応
        - ${DB_PORT}:3306
    environment:
        MYSQL_DATABASE: ${DB_NAME}
        MYSQL_USER: ${DB_USER}
        MYSQL_ROOT_PASSWORD: ${DB_PASS}
        MYSQL_PASSWORD: ${DB_PASS}
    container_name: ${MYSQL_CONTAINER}

${DB_USER}がrootになってるみたいなので、MYSQL_USER: ${DB_USER}MYSQL_PASSWORD: ${DB_PASS}をコメントアウト。再度、docker-compose upを実行。

[+] Running 3/3
 ✔ Container laravel_todo_php    Running                                                                                  0.0s 
 ✔ Container laravel_todo_mysql  Started                                                                                  2.4s 
 ✔ Container laravel_todo_pma    Started  

無事起動しました!!!一安心。

参考にさせていただいた記事はこちら!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?