72
50

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 3 years have passed since last update.

docker + mysql が接続できない... Access denied for user 'homestead'@'172.20.0.1' (using password: YES)

Last updated at Posted at 2020-01-28

問題

db のコンテナを立ててアプリからつなぐ際に、接続ができない。

ログ

Access denied for user 'root'@'172.18.0.5' (using password: YES)

docker-compose.yml

docker-compose.yml
version: "3"
services:
  db:
    image: mysql:8.0.19
    ports:
      - 13306:3306
    volumes:
      - db-store:/var/lib/mysql
      - ./logs:/var/log/mysql
      - ./docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=homestead
      - MYSQL_USER=homestead
      - MYSQL_PASSWORD=secret
      - TZ=${TZ}
volumes:
  db-store:

#解決策
volumeを削除したらできました。

#削除方法

$ docker-compose down --volumes
$ docker-compose up -d --build

down コマンド時に --volumes オプションを付けるとコンテナと名前付きボリュームの削除が出来るらしい。知らなかった。。。

#参考にした記事
docker-compose MySQL8.0 のDBコンテナを作成する
https://qiita.com/ucan-lab/items/b094dbfc12ac1cbee8cb

72
50
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
72
50

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?