Real-world Rails development with Docker (Part 3)

Series Index

Part 1: Introduction
Part 2: Setup
Part 3: Controlling the stack
Part 4: The Rails app
Part 5: Gotchas and final thoughts

Controlling the stack

From the root of our docker-demo-stack repo, open two shell sessions.

In the first session, let’s run the monitoring script. This will initially show nothing, but as our containers are built and started, the value of this script will become apparent:

$ monitor.sh

You should see something like this:

watch-1

In the second session, let’s start up our stack. The script will download any required Docker images and then build any containers that don’t already exist.

$ start.sh

When doing this for the first time, you will probably see a ton of things being downloaded. This is normal, and once you have the images downloaded, you can create, destroy and recreate containers very quickly.

You should see something like this:

start-1

Pay attention to your monitoring session now. See what’s happened? You now have 5 containers up and running, together with 2 data volumes.

watch-2

We can stop everything just as easily as starting it up:

$ stop.sh

stop-1

Notice that our containers now have a new status:

watch-3

Want to remove everything? No problem, run our teardown script:

$ teardown.sh

Our monitoring session shows that everything has been removed. Let’s rebuild it again…

$ setup.sh
$ start.sh

rebuild

Easy!

Checking local DNS

Let’s make sure we have a working DNS configuration. In your browser, navigate to http://demo.docker.localdev

You should see our custom error page being served by Nginx in our Docker container.

nginx-error

I’ve also created a self-signed SSL certificate, which we should setup now. Navigate to https://demo.docker.localdev

You should get a security warning. Follow these instructions to trust the certificate. Open a new browser tab and you should have a secure connection:

secure

Checking PostgreSQL

You should be able to connect to PostgreSQL on the default port using the postgres superuser. This user was setup in the templates/init-user-db.sh script.

postgres

Checking Elasticsearch

Navigate to http://127.0.0.1:9200/_search?pretty=true

You should see a JSON response from Elasticsearch.

Sweet! We are now ready to start our Rails app…

Go to Part 4: The Rails app

Leave a comment