Docker Passenger Dashboard shows MySQL can't connect to socket

I’m Trying to deploy Ruby on Rails app on phusion/passenger-ruby21 container and a separate mysql:5.5.46 container. Both are linked without docker compose.

I ran Passenger-ruby container with:
sudo docker run -it -p 80:80 --link mysql55:mysql -e .env --name ror1 rubyonrails-phusionimg2 /bin/bash

mysql container with:
sudo docker run --detach --name mysql55 --env MYSQL_ROOT_PASSWORD=**** --env MYSQL_USER=**** --env MYSQL_PASSWORD=**** --env MYSQL_DATABASE=**** mysql:5.5.46

  • how to set the service mode when using docker compose?
  • Docker and Java IDE integration
  • 502 error when viewing Java liberty Bluemix application using Docker container
  • Ansible docker_container gives “Error getting network id”
  • GitLab Ci with docker runner - Multiple Stages
  • Running and debugging an ASP.NET Core RC2 application in Docker
  • this is my database.yml in the Rails app.

      adapter: mysql2
      database: "<%= ENV["DATABASE_NAME"] %>"
      host: "<%= ENV["MYSQL_PORT_3306_TCP_ADDR"] %>"
      port: "<%= ENV["MYSQL_PORT_3306_TCP_PORT"] %>"
      username: "<%= ENV["DATABASE_USERNAME"] %>"
      password: "<%= ENV["DATABASE_STAGING_PASSWORD"] %>"

    Here is webapp.conf:

    # /etc/nginx/sites-enabled/webapp.conf:
     server {
        listen       80;
        server_name  *****.com;
        root /home/app/webapp/public;
        passenger_enabled on;
        rails_env staging;
        index index.html index.htm;
        # auth_basic "Restricted";
        # auth_basic_user_file /etc/nginx/htpasswd;

    rake db:create db:migrate runs successfully, which means that the rake program with staging environments is able to reach the mysql database container. But from the passenger dashboard I’m still getting the Can't connect to local MySQL server through socket /var/run/mysqld/mysqld.sock (2)

    Am i missing something? All env’s seem to be loaded and correct.

  • Docker Remote API Build with Node and Dockerode
  • Docker Build and Multi layer dll version
  • Docker container cannot resolve request to service in another container
  • Docker container loosing network when my host machine switches network (Mac OSX)
  • How to run custom Docker file?
  • Best practice: Python development environment with docker for mac
  • 2 Solutions collect form web for “Docker Passenger Dashboard shows MySQL can't connect to socket”

    You don’t specify host of connection to mysql in your application.

    If you don’t specify host mysql will try to connect the server on you host not the one in the container.

    I changed mysql database env variables in apps database.yml file which are preloaded when container is started and connected to mysql database. For example “DATABASE_NAME” to “MYSQL_ENV_MYSQL_DATABASE”.

      adapter: mysql2
      database: <%= ENV['MYSQL_ENV_MYSQL_DATABASE'] %>
      host: <%= ENV['MYSQL_PORT_3306_TCP_ADDR'] %>
      port: <%= ENV['MYSQL_PORT_3306_TCP_PORT'] %>
      username: <%= ENV['MYSQL_ENV_MYSQL_USER'] %>
      password: <%= ENV['MYSQL_ENV_MYSQL_PASSWORD'] %>`
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.