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

  • Docker-Compose Up Works but Eb Local Run does not
  • Pass parameter to Docker without -e flag
  • How to use docker container as apache server?
  • Unable to connect to Jupyter Notebook served by Docker
  • Dockerfile entrypoint script arguments in docker run
  • Challenges in upgrading Docker components
  • 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.

  • Pulling docker images behind a proxy
  • Why are my mounted docker volume files turning into folders inside the container?
  • Project Atomic - Cockpit doesnt install through Vagrant
  • docker-compose yml running a script after up
  • Docker - free up space after removing all images & containers
  • How to create populated MySQL Docker Image on build time
  • 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.