docker.local hostname in /etc/hosts not resolving on OSX for docker machine (causing rspec tests to fail)

I had a bug today where my rspec tests ran fine, down to the last expectation, but then I still got a “database connection timeout error”.

This is running rails locally, connecting to a postgres instance inside of docker, using docker machine.

  • Is there a way to “hibernate” a linux container
  • ECS will not launch instance, “unable to place a task because the resources could not be found.”
  • Docker container drive does not match available hard drive space on host
  • How to see the logs of running application inside docker container?
  • Exception occuring when updating database schema in symfony
  • docker run from systemd service starts but exits immediately, and restarts, but docker run from shell works fine
  • Docker machine instructions guided me to create an entry in my /etc/hosts file: docker.local 

    This worked fine for the test itself, but then something (probably some cleanup step after the test suite – possibly from DatabaseCleaner?) still raised an error about timing out connecting to the database.

    After a lot of investigation, debugging, even deleting and recreating the docker machine default container, I finally narrowed it down to if I replace docker.local with the actual IP address in the database config – it passes.

    So bottom line – some cleanup process didn’t have access to the /etc/hosts defined docker.local hostname.

    This is on OSX El Capitan.

  • Getting “Invalid address” error on gunicorn bind with my server ip . i am trying this within the docker
  • Docker echo to /etc/hosts not working
  • Connection between docker container
  • How to change permissions of a docker mounted volume on OSX to work with Nginx web server running Laravel 5.1?
  • Redis Server docker container connect to another docker container can only work with bind all
  • Managing a group of docker containers without the sweat
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.