前提・実現したいこと
docker環境でlocalのmysqlに接続したいがサービー接続後エラーが出てしまう。
発生している問題・エラーメッセージ
Access denied for user 'root'@'172.18.0.3' (using password: NO)
該当のソースコード
dockercomposeyml
1version: '3' 2services: 3 db: 4 image: mysql:5.6.47 5 environment: 6 - MYSQL_ROOT_PASSWORD=root 7 - MYSQL_DATABASE=match_hike_development 8 - MYSQL_USER=root 9 - MYSQL_PASSWORD= 10 ports: 11 - '3306:3306' 12 web: 13 build: 14 context: . 15 dockerfile: Dockerfile 16 command: bundle exec rails s -p 3000 -b '0.0.0.0' 17 tty: true 18 stdin_open: true 19 depends_on: 20 - db 21 ports: 22 - "3000:3000" 23 volumes: 24 - .:/application 25volumes: 26 mysql-data: 27 driver: local
databaseyml
1# MySQL. Versions 5.5.8 and up are supported. 2# 3# Install the MySQL driver 4# gem install mysql2 5# 6# Ensure the MySQL gem is defined in your Gemfile 7# gem 'mysql2' 8# 9# And be sure to use new-style password hashing: 10# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html 11# 12default: &default 13 adapter: mysql2 14 encoding: utf8mb4 15 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 16 username: root 17 password: 18 socket: /tmp/mysql.sock 19 20development: 21 <<: *default 22 database: match_hike_development 23 24# Warning: The database defined as "test" will be erased and 25# re-generated from your development database when you run "rake". 26# Do not set this db to the same as development or production. 27test: 28 <<: *default 29 database: match_hike_test 30 31# As with config/credentials.yml, you never want to store sensitive information, 32# like your database password, in your source code. If your source code is 33# ever seen by anyone, they now have access to your database. 34# 35# Instead, provide the password as a unix environment variable when you boot 36# the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database 37# for a full rundown on how to provide these environment variables in a 38# production deployment. 39# 40# On Heroku and other platform providers, you may have a full connection URL 41# available as an environment variable. For example: 42# 43# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" 44# 45# You can use this database configuration with: 46# 47# production: 48# url: <%= ENV['DATABASE_URL'] %> 49# 50production: 51 adapter: mysql2 52 encoding: utf8 53 pool: 5 54 database: match_hike_production 55 username: root 56 password: 57 socket: /var/lib/mysql/mysql.sock
terminal
1$ docker exec -it match_hike_db_1 bash -c "mysql -u root -proot" 2Warning: Using a password on the command line interface can be insecure. 3Welcome to the MySQL monitor. Commands end with ; or \g. 4Your MySQL connection id is 4 5Server version: 5.6.47 MySQL Community Server (GPL) 6 7Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. 8 9Oracle is a registered trademark of Oracle Corporation and/or its 10affiliates. Other names may be trademarks of their respective 11owners. 12 13Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 14 15mysql> show databases; 16+------------------------+ 17| Database | 18+------------------------+ 19| information_schema | 20| data | 21| match_hike_development | 22| mysql | 23| performance_schema | 24+------------------------+ 255 rows in set (0.04 sec) 26 27mysql>
試したこと
volumeの削除
コンテナの削除、作り直し
補足情報(FW/ツールのバージョンなど)
Docker version 19.03.8, build afacb8b
macOS
ruby 2.5.1
rails 6.0.3.1
mysql 5.6.47
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。