The Rails app
Check out the demo application source code and prepare the application.
$ git clone email@example.com:edjames/docker-demo-app.git $ cd docker-demo-app $ bundle install $ rake db:migrate
Over in our docker-demo-stack, make sure that the path we mount in the Nginx container actually mounts the correct path to your demo Rails app. This is in the
docker-compose.yml file at this line:
You can use a relative or absolute path, just ensure that the part on the left of the colon is a valid path to your Rails app.
Now start up the Rails app:
$ foreman start
Our application should start and we can hit the homepage now. Navigate to https://demo.docker.localdev
We already have a simple model, so navigate to https://demo.docker.localdev/things
Create a few records, perform a few edits, destroy some things. Just make sure you make at least 10 or so requests.
This proves we have database connectivity.
To ensure we have cache connectivity, open a Rails console and do the following:
$ rails c >> Rails.cache.read 'docker-demo' => nil >> Rails.cache.write 'docker-demo', 'rocks!' => 288230376151711744 >> Rails.cache.read 'docker-demo' => "rocks!" >> Rails.cache.clear => [true] >> Rails.cache.read 'docker-demo' => nil
Cache is good!
Navigate to https://demo.docker.localdev/jobs/busy
Enable live polling and you should see a test job being executed every 10 seconds.
Redis is good!
Navigate to http://127.0.0.1:5601
Let Kibana load. In the “Index name or pattern” form field, change
filebeat.* and click “Create”:
Click on “Discover”. Add a few fields. You have just setup awesome unified logs in Elasticsearch!
Points of interest
There are a couple of things I have done in this otherwise vanilla Rails app which allow for all this to happen.
- I bind the Rails server (puma) to port
192.168.0.99. See the
Procfile. This matches the port we use in the setup step, when we create an alias to
- I’ve added the
logragegem with some additional configuration in the
- I run a
filebeatprocess which handles log forwarding to Elasticsearch.
Other than binding to the port described in , the Rails app has no knowledge of the fact that the underlying stack is running in Docker containers.