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

  • Why does not work docker command in MacOS?
  • How can I use a local image as the base image with a dockerfile?
  • Running docker image does not work
  • Docker, Cannot connect to the Docker daemon. Is the docker daemon running on this host?
  • How should I pass sensitive environment variables to Amazon ECS tasks?
  • can we update docker default configure?
  • 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.

  • I could curl using IP but not using consul serviceName?
  • Python3 in DockerFile running ubuntu::latest
  • Cannot connect Docker container to Weave network
  • Docker-machine error in Linux
  • Is this possible to get all running containers id's in docker swarm services?
  • How to extend an existing docker image?
  • 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.