問題
db のコンテナを立ててアプリからつなぐ際に、接続ができない。rails から db createできない
ログ
Access denied for user 'root'@'172.18.0.5' (using password: YES)
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "reconnect"=>false, "pool"=>5, "timeout"=>5000, "host"=>"db", "username"=>"root", "password"=>"pass", "port"=>3306,
docker logs
Version: '5.7.22' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
2018-06-29T01:49:15.357922Z 2 [Note] Access denied for user 'root'@'172.18.0.3' (using password: YES)
2018-06-29T01:49:50.804587Z 3 [Note] Access denied for user 'root'@'172.18.0.5' (using password: YES)
2018-06-29T01:49:54.664363Z 4 [Note] Access denied for user 'root'@'172.18.0.5' (using password: YES)
docker-compose.yml
version: '3'
services:
db:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=pass
ports:
- '3306:3306'
volumes:
- db-data:/var/lib/mysql
Access denied for user 'root'@'172.18.0.5' (using password: YES)
やったこと
・root以外のユーザーを作成、ユーザー名、パスワードなどを変更
・5.6に変更
・再起動
解決策
volumeを消したら行けた。。
https://github.com/docker-library/mysql/issues/51
名前付きのvolumeを使っていたので
docker volume rm servicename_db-data