Home>

I was able to deploy the application created by ruby ​​on rails using docker on heroku, but after that, when I tried to start the server with open app, the following error occurred.

2020-11-17T09: 56: 26.289345 + 00: 00 app [web.1]: I, [2020-11-17T09: 56: 26.289248 # 4] INFO-: [88fc03a5-b2fd-4739-b340-5c674cdeda14] Completed 500 Internal Server Error in 3ms
2020-11-17T09: 56: 26.290648 + 00: 00 app [web.1]: F, [2020-11-17T09: 56: 26.290568 # 4] FATAL-: [88fc03a5-b2fd-4739-b340-5c674cdeda14]
2020-11-17T09: 56: 26.290688 + 00: 00 app [web.1]: F, [2020-11-17T09: 56: 26.290641 # 4] FATAL-: [88fc03a5-b2fd-4739-b340-5c674cdeda14] Mysql2 :: Error :: ConnectionError (Unknown MySQL server host'db' (0)):
Corresponding source code

The source code is as follows.
docker-compose.yml

version: '3'
services: services:
    db:
        image: mysql: 5.7
        environment: environment:
            MYSQL_USER: root
            MYSQL_ROOT_PASSWORD: password
        ports: ports:
            -"3306: 3306"
        volumes:
            --./db/mysql/volumes:/var/lib/mysql
    web:
        build: ..
        command: bash -c "rm -f tmp/pids/server.pid&&bundle exec rails s -p 3000 -b '0.0.0.0'"
        volumes:
            --.:/Myapp
            --gem_data:/usr/local/bundle
        ports: ports:
            --3000: 3000
        depends_on:
            --db
        tty: true
        stdin_open: true
volumes:
  gem_data:


database.yml

default:&default
  adapter: mysql2
  encoding: utf8
  pool:<% = ENV.fetch ("RAILS_MAX_THREADS") {5}%>
  username: root
  password: password
  host: db
development:
<<: * default
  database: myapp_development
test: test:
<<: * default
  database: myapp_test
production:
<<: * default
  database: myapp_production
  username: myapp
  password:<% = ENV ['MYAPP_DATABASE_PASSWORD']%>
What I tried

I searched all kinds of sites, but I couldn't find a clue to the solution, and I was confused.
I'm a beginner and there are many things I don't understand, but I'd appreciate it if you could teach me anything. Thank you.

Supplementary information (FW/tool version, etc.)
  • Answer # 1

    The host in database.yml is different.
    If mysql is running on the same server
    host: localhost

    is.
    Maybe it is necessary to set socket:

  • Answer # 2

    The host in database.yml is different.
    If mysql is running on the same server
    host: localhost

    is.
    Possibly socket: setting m

Related articles