{"id":15512925,"url":"https://github.com/jfroom/docker-compose-rails-selenium-example","last_synced_at":"2026-04-01T23:33:38.935Z","repository":{"id":152817600,"uuid":"85011590","full_name":"jfroom/docker-compose-rails-selenium-example","owner":"jfroom","description":"Docker Compose 3 techniques for: Rails 5.0 dev \u0026 Travis CI, caching bundler gems, and using selenium-webdriver.","archived":false,"fork":false,"pushed_at":"2018-02-26T18:01:26.000Z","size":34,"stargazers_count":52,"open_issues_count":1,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-29T14:39:23.624Z","etag":null,"topics":["bundler","docker-compose","rails","selenium-webdriver","travis-ci","vnc"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jfroom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-15T00:41:05.000Z","updated_at":"2024-12-13T22:36:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"4b1b4cc5-0ebe-4c5e-9f58-e31e4cd18668","html_url":"https://github.com/jfroom/docker-compose-rails-selenium-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jfroom/docker-compose-rails-selenium-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfroom%2Fdocker-compose-rails-selenium-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfroom%2Fdocker-compose-rails-selenium-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfroom%2Fdocker-compose-rails-selenium-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfroom%2Fdocker-compose-rails-selenium-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jfroom","download_url":"https://codeload.github.com/jfroom/docker-compose-rails-selenium-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfroom%2Fdocker-compose-rails-selenium-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010939,"owners_count":26084837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bundler","docker-compose","rails","selenium-webdriver","travis-ci","vnc"],"created_at":"2024-10-02T09:53:56.132Z","updated_at":"2025-10-12T09:31:52.208Z","avatar_url":"https://github.com/jfroom.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# docker-compose-rails-selenium-example [![Build Status](https://travis-ci.org/jfroom/docker-compose-rails-selenium-example.svg?branch=master)](https://travis-ci.org/jfroom/docker-compose-rails-selenium-example)\n\nJust a few Docker Compose 3 techniques for integrating:\n- Rails 5.0 development \u0026 Travis CI tests\n- Caching of bundler gems into a Docker volume which persists across builds and Gemfile changes\n- A Selenium Chrome standalone instance running Capybara tests, and a VNC connection to interact with the test browser session\n\nThese insights took a while to grasp — so I'm sharing in case someone else finds it useful.\n\nNew to Docker \u0026 Rails? Unfamiliar with the issues surrounding the topics above? Start with the links in [References](#references).\n\n# Getting started\n\n## Required\n\n1. Install [Docker](https://www.docker.com/) 17.03.0-ce+. This should also install Docker Compose 1.11.2+.\n2. Verify versions: `docker -v; docker-compose -v;`\n\n## Recommended\n1. Install [VNC Viewer](https://www.realvnc.com/download/viewer/) to view \u0026 interact with selenium sessions that would otherwise be headless.\n\n# Rails app\n\nThis base Rails app is very simple since the focus here is on docker. \n- Was setup with `rails new app --skip-active-record`. The database was skipped to stay lightweight.\n- It has one root path route to the WelcomeController which renders \"Hello World!\" from `views/welcome/index.html.erb`\n\n# Basic Docker Commands\n\n### First run\n\n`docker-compose build` Builds images.\n\n### Run\n\n`docker-compose up` Installs gems, launches web server.\n\n`open http://localhost:3000` Once the server is up, the root page can be seen on your local machine.\n\n### Test\n\n`docker-compose test` Ensure the services are already 'up' in another terminal, or in detached mode, before running tests.\n\n`vnc://localhost:5900 password:secret` To watch the selenium tests run, use VNC to connect to the Selenium service. [VNC Viewer](https://www.realvnc.com/download/viewer/) works well, and on OS X Screen Sharing app is built-in. To interact and debug a browser session, add `byebug` into the test to stop the driver.\n\n# Docker Setup\n\n## Docker \u0026 Bundler Cache\n\n[Bundler](http://bundler.io/) installs and keeps track of all the gem libraries. Keeping docker container build times low is not trivial when bundler is involved. It took some time \u0026 research to optimize bundler's cache, so is worth an explanation. Credit to the unboxed team for this [bundler cache technique](https://unboxed.co/blog/docker-re-bundling/) — I've made some changes to make it compatible for Docker Compose 3 (which doesn't support `volume_from`). The gist of it:\n\n`Dockerfile`:\n- `ENTRYPOINT [\"/docker-entrypoint.sh\"]` allows a shell script to run before any relative containers execute a command.\n- `ENV BUNDLE_PATH=/bundle BUNDLE_BIN=/bundle/bin GEM_HOME=/bundle` configures a new installation path for future bundler installs, and binstubs.\n- `ENV PATH=\"${BUNDLE_BIN}:${PATH}\"` allows bundler's binstubs to be executed without `bundle exec` (i.e. `puma`)\n\n`docker-entrypoint.sh`:\n- Ensures all gems are installed before the web services boot up. This happens everytime `docker-compose up` executes.\n- Gems are installed to `/bundle` in the docker instance because of the defined `BUNDLE_PATH` env var above.\n- `bundle install --binstubs=\"$BUNDLE_BIN\"` installs the gems and stub commands are available because they were defined on PATH above.\n\n`docker-compose.yml`:\n- `version: '3.1'` Volume syntax changed a bit between 2 and 3 (volume_from was removed)\n- `services:web:volumes:` defines `bundle_cache:/bundle`, and then `volumes:bundle_cache` persists it across builds. **This reduces build times for local development. :tada:** \n- When installing a new gem, or changing branches which have different gems — just stop the docker services and restart it. Or execute `bundle install` on the container. The old gems are already cached, and only new gems will be installed.\n\n## Docker \u0026 Rails\n\n`docker-compose.override.yml`\n- This file is automatically used during a standard `docker-compose up`. \n- Has a muliline `services:web:command` that starts the development (port 3000) \u0026 test (port 3001) servers. This could move that into a script file, but I like having a flatter architecture, and there's one less file to chase down.\n- Runs dedicated test server which is bound to the test database to debug the test environment, and fewer differences between dev \u0026 CI environments.\n- Exposes web ports to host machine so you can visit 'http://localhost:3000' for development server, and 'http://localhost:3001' for test server. \n- See Travis CI section for why the command and ports had to be split out into an override file (vs. just putting directly into the `docker-compose.yml` file.\n\n## Docker \u0026 Selenium\n\n`Gemfile`\n- Has `selenium-webdriver` and `minitest-rails-capybara` in the `:test` group.\n\n`docker-compose.yml`\n- Defines `services:selenium` with the `selenium/standalone-chrome-debug` image\n- The VNC service included with the debug is really useful for debugging (see commands section).\n- Defines several enviornment variables which help link Capybara to the Docker network: `SELENIUM_HOST SELENIUM_PORT TEST_APP_HOST TEST_PORT`\n\n`test/test_helper.rb`\n- Uses the env variables defined above in the Capybara configuration.\n\n`test/acceptance/welcome_page_test.rb`\nShows a simple test case to visit the root path, and confirms **'Hello World!'** is rendered.\n\n## Docker \u0026 Travis CI\n\n`docker-compose.ci.yml`\n- Command launches the test server.\n- Configures ports that are only exposed to the Docker network — not to the host machine. Travis was blocking some of the external ports.  \n- This override file is executed in `.travis.yml` as: `docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d`\n\n# References\nNew to Docker \u0026 Rails? Unfamiliar with the issues surrounding the topics above? Start here. Much of this repo is an derivative \u0026 build upon the content of these quality resources:\n\nDocker \u0026 Rails:\n- [Dockerize a Rails 5, Postgres, Redis, Sidekiq and Action Cable Application with Docker Compose](https://nickjanetakis.com/blog/dockerize-a-rails-5-postgres-redis-sidekiq-action-cable-app-with-docker-compose) (Nick Janetakis)\n\nDocker \u0026 Bundler:\n- [Make bundler fast again in Docker Compose](http://bradgessler.com/articles/docker-bundler/) (Brad Gessler)\n- [Development Re-bundling in Dockerland](https://unboxed.co/blog/docker-re-bundling/) (Charlie Egan)\n\nDocker \u0026 Selenium:\n- [Dockerized Rails Capybara Tests On Top Of Selenium](http://www.alfredo.motta.name/dockerized-rails-capybara-tests-on-top-of-selenium/) (Alfredo Motta)\n- [Docker container for running browser tests](https://medium.com/@georgediaz/docker-container-for-running-browser-tests-9b234e68f83c) (George Diaz)\n\nDocker \u0026 Travis:\n- [Travis - Using Docker in Builds](https://docs.travis-ci.com/user/docker/) (TravisCI)\n- [Managing Docker \u0026 Docker Compose versions on Travis](https://graysonkoonce.com/managing-docker-and-docker-compose-versions-on-travis-ci/) (Grayson Koonce)\n\n# License\nCopyright © JFMK, LLC Released under the [MIT License](https://github.com/jfroom/docker-compose-rails-selenium/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjfroom%2Fdocker-compose-rails-selenium-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjfroom%2Fdocker-compose-rails-selenium-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjfroom%2Fdocker-compose-rails-selenium-example/lists"}