お世話になっております。
現在、LuggageMGTというアプリ作成しています。
勉強で、Docker環境でcircleCIを使用しております。
解決したいこと、エラー
ローカルのターミナルにて、docker-compose upをすると、
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2 "No such file or directory")
と出てしまいます。
#実行したこと
/tmp/mysql.sockが存在するか下記コマンドで確認しました
% mysql_config --socket /tmp/mysql.sock
下記コマンドでMySQLを再起動させました。
% mysql.server restart Shutting down MySQL .. SUCCESS! Starting MySQL .. SUCCESS!
きちんとファイルは存在するのに、
(2 "No such file or directory")
と出る理由も分かりません。
下記に該当してそうなファイルを記述致します。
まだまだ知識が甘く、変なところもあるかもしれないです。よろしくお願い致します。
database.yml
# MySQL. Versions 5.1.10 and up are supported. # # Install the MySQL driver # gem install mysql2 # # Ensure the MySQL gem is defined in your Gemfile # gem 'mysql2' # # And be sure to use new-style password hashing: # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html # default: &default adapter: mysql2 encoding: utf8 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root password: password host: localhost socket: /tmp/mysql.sock development: <<: *default database: LuggageMGT_development # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: LuggageMGT_test # As with config/secrets.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is # ever seen by anyone, they now have access to your database. # # Instead, provide the password as a unix environment variable when you boot # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database # for a full rundown on how to provide these environment variables in a # production deployment. # # On Heroku and other platform providers, you may have a full connection URL # available as an environment variable. For example: # # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" # # You can use this database configuration with: # # production: # url: <%= ENV['DATABASE_URL'] %> # production: <<: *default database: LuggageMGT_production username: root password: <%= ENV['DATABASE_PASSWORD'] %> socket: /tmp/mysql.sock
docker-compose.yml
version: '3' services: web: build: . ports: - "3000:3000" tty: true command: /bin/sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" volumes: - .:/app_name depends_on: - db db: image: mysql:5.6.47 environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: root ports: - "3306:3306" volumes: - ./tmp/db:/var/lib/mysql/data volumes: bundle: mysql_data:
dockerfile
FROM ruby:2.5.3 RUN apt-get update -qq && \ apt-get install -y build-essential \ libpq-dev \ nodejs RUN mkdir /app_name ENV APP_ROOT /app_name WORKDIR $APP_ROOT ADD ./Gemfile $APP_ROOT/Gemfile ADD ./Gemfile.lock $APP_ROOT/Gemfile.lock RUN bundle install ADD . $APP_ROOT
circleci/config.yml
version: 2.1 orbs: ruby: circleci/ruby@0.1.2 jobs: build: docker: - image: circleci/ruby:2.5.3-stretch-node - image: circleci/mysql:5.6.47 environment: MYSQL_ROOT_PASSWORD: "password" MYSQL_ROOT_HOST: "%" working_directory: ~/LuggageMTG executor: ruby/default steps: - checkout - run: name: Which bundler? command: bundle -v - ruby/bundle-install
追記です。
database.ymlです。
# MySQL. Versions 5.1.10 and up are supported. # # Install the MySQL driver # gem install mysql2 # # Ensure the MySQL gem is defined in your Gemfile # gem 'mysql2' # # And be sure to use new-style password hashing: # https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html # default: &default adapter: mysql2 encoding: utf8 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root password: password host: localhost development: <<: *default database: LuggageMGT_development # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: LuggageMGT_test # As with config/secrets.yml, you never want to store sensitive information, # like your database password, in your source code. If your source code is # ever seen by anyone, they now have access to your database. # # Instead, provide the password as a unix environment variable when you boot # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database # for a full rundown on how to provide these environment variables in a # production deployment. # # On Heroku and other platform providers, you may have a full connection URL # available as an environment variable. For example: # # DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase" # # You can use this database configuration with: # # production: # url: <%= ENV['DATABASE_URL'] %> # production: <<: *default database: LuggageMGT_production username: root password: <%= ENV['DATABASE_PASSWORD'] %> socket: /var/lib/mysql/mysql.sock
host: dbをlocalhostにしたりしたのですが、現状何も変わっておりません。
お力を貸してください....。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。