Moving to 2.0 with a non-dockerized Rails app, `ActiveRecord::NoDatabaseError: FATAL: role "root" does not exist`



I’m moving a standard, non-dockerized, Rails app that is deployed to Heroku to Circle2.0 using the docker executor. I have very little Docker experience, so firstly, is this sensible, or should I be using the machine executor? I like the Docker approach.

I have managed to get many of the basic steps to work (installing dependencies and bundle install) on the host machine. Then I run into trouble when I’m trying to create my database.

When running this line bundle exec rake db:create db:schema:load --trace I get the following error:

** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:create
FATAL:  role "root" does not exist

So I seem to be connecting to the Postgres container (since there is no Postgres installed in the ruby container), but then for some reason that doesn’t appear to be configured correctly. Is my conclusion correct? In either case, suggestions would be really helpful.

This is my config.yml so far:

 version: 2
      - image: ruby:2.2.2
          RAILS_ENV: test
          RACK_ENV: test
          PG_HOST: localhost
          PG_USER: ubuntu
      - image: postgres:9.4.1
          POSTGRES_USER: ubuntu
          POSTGRES_DB: circle_ruby_test

    working_directory: ~/copyin
      - checkout
      - run: echo "USING CIRCLE 2.0"
      - run:
          name: Install System Dependencies
          command: apt-get update -qq && apt-get install -y build-essential nodejs
      - run:
          name: Install rmagick dependencies
          command: apt-get install libmagickwand-dev imagemagick imagemagick-6.q16 libmagickcore-dev
      - run:
          name: Symlink imagemagick dependencies
          command: ln -s /usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/bin-Q16/Magick-config /usr/bin/Magick-config
      - run:
          name: Install capybara-webkit dependencies
          command: apt-get install --assume-yes qt5-default libqt5webkit5-dev
      - run:
          name: Install latest version of Bundler
          command: gem install bundler
      - restore_cache:
          key: Gemfile-{{ checksum "Gemfile.lock" }}
      - run:
          name: Install Ruby Dependencies
          command: bundle install
      - run: bundle show rails
      - save_cache:
          key: Gemfile-{{ checksum "Gemfile.lock" }}
            - /usr/local/bundle/gems/
      - run:
          name: Create DB
          command: bundle exec rake db:create db:schema:load --trace
      - run:
          name: Run Tests
          command: bundle exec rspec --drb --colour --order rand


I definitely recommend using the Docker executor like you are, but you should build your own image. It really speeds up your builds when all your dependencies are baked in. If you don’t have any private gems, you can even install your Ruby dependencies on the image; that cuts your config into about a quarter of the size it is now.

You probably need PGUSER instead of PG_USER since you’re hitting that error. If the issue persists, you should add it to your database config.


@rohara thanks for the quick response. PGUSER was indeed the fix, weirdly in all the examples it was PG_USER.

As for bundling all the dependencies inside of a container, that is a great idea, should have thought of that already :stuck_out_tongue:


@rohara I have another question that is in the same vein, related to an external docker image from the host so I figured I’d ask it here instead of opening a new thread.

I’m trying to run Selenium for my integration tests. The documentation makes it seem like its as simple as adding - image: selenium/standalone-firefox:3.1.0 in config.yml, but this is not the case for me. I get the following error.

Selenium::WebDriver::Error::WebDriverError: Could not find Firefox binary (os=linux). Make sure Firefox is installed or set the path manually with Selenium::WebDriver::Firefox::Binary.path=

I use capybara-webkit to run the tests so I assume it is related to this, but the documentation seems to imply that if I had this working on 1.0, that with the external image it should also just work on 2.0 - which is why I’m not sure what to do in the docker world.

I have tried the config below, is this remotely in the right direction?

Capybara::Webkit.configure do |config|
  config.use_proxy(host: "localhost", port: 4444)

Thanks again for your help.


Awesome questions! I also had some confusion with the mismatched information regarding PGUSER and PG_USER - maybe different version of Postgres.

While you have Selenium accessible, Capybara is still expecting Firefox to be accessible in $PATH. I solved this by just installing firefox-esr and re-running the build. It seemed okay with having Selenium accessible via TCP as long as Firefox was in the $PATH.


@rohara I’m not sure in what way you installed firefox-esr. Is this a different docker image from selenium/standalone-firefox?

If I do this, will it be running Firefox in the host container or the selenium container? Sadly this container world is still a bit foreign!

Thanks for the great support.


No worries! The Selenium setup is definitely confusing.

Yes, it is a different image from the selenium/standalone-firefox image. Installing firefox-esr on your base image will allow the tests to run. You still need to have selenium/standalone-firefox as a running image so you can connect to it. The tests run in the Selenium container.

I’m still a bit unclear on some of the specifics on how certain test suites are interacting with the browsers in $PATH and passing information to Selenium. It seems like having the browser installed is superfluous and the libraries are not respecting a containerized environment.


So to try this out without building my own container image (which I will do once it all works) I just added this line to my config.yml.

       - run:
           name: Install Firefox-esr for selenium
           command: apt-get install --assume-yes firefox-esr

Then when I run my tests, I get a slightly different error:

Selenium::WebDriver::Error::WebDriverError: unable to obtain stable firefox connection in 60 seconds (

This happens both when I have Capybara configured to use a proxy and not. It seems clear to me that the binary (firefox-esr) is now being found, but that it is still struggling to connect to selenium. Do you support this interpretation? I realise that this is indeed a confusing, unclear problem as you’ve said yourself, but hopefully this thread will end up also being a resource for others once I get it running.


We probably just need to start a display. Install xvfb and start it as a background process

- run:
    command: Xvfb :99
    background: true

You also need to define this env var in your circle.yml:

      DISPLAY: ":99"


@rohara that makes total sense. I’ve got my tests running now, thanks again!

Now to actually start fixing some sporadic tests :stuck_out_tongue:

closed #11