Skip to content

Instructions for Local Setup with Docker

Brad Bergeron edited this page Jul 18, 2017 · 8 revisions

Docker Install and Setup

Docker and docker-compose installation in Mac OS

  1. Download docker.dmg Download Docker for Mac
  2. Double-click Docker.dmg to open the installer, then drag Moby the whale to the Applications folder.
  3. Double-click Docker.app in the Applications folder to start Docker. 4.Make sure Docker has installed properly by running following commands in terminal. $ docker --version $ docker-compose --version

Docker and docker-compose installation in Windows.

  1. Download Docker MSI Download docker for Windows
  2. Double-click Install Docker.msi to run the installer.
  3. Follow the install wizard to accept the license, authorize the installer, and proceed with the install.
  4. Click Finish on the setup complete dialog to launch Docker.

Spinning up the Application with Docker for Development

1. Create a directory Example: docker-dev

$ mkdir docker-dev
$ cd docker-dev

2. Download the code from github to docker-dev directory.

$ git clone https://github.com/Service-Alliance/Service_Phase_1.git

3. Move Dockerfile and docker-compose.yml, to docker-dev/Service_Phase_1 directory.

$ mv docker-compose.yml Dockerfile Service_Phase_1

4. After completion of above 3 steps docker-dev/Service_Phase_1 directory should be looking like below. List the files.

$  ls -lahg

Files in Docker-Dev

5. By default, Rails expects a database to be running on localhost - so you need to point it at the db container instead. You also need to change the database and username to align with the defaults set by the Postgres image by deleting the text config/database.yml and pasting in the code in its place.

default: &default
 adapter: postgresql
 encoding: unicode
 pool: 5
 development:
   <<: *default
   database: development
   username: postgres
   # password: password
   host: db
   port: 5432

5. Run below command to build web & db images. It will also spin up containers.

$ docker-compose up -d

6. With these settings in place,finally create and set up the database by running following command in another terminal.

$ docker-compose run web rake db:create db:setup
  1. After completion of above steps You should be able to access the application via a web browser by visiting the http://localhost:3000

Stopping the project

1. To stop and spin-down the application, run docker-compose down.

$ docker-compose down

2. You can also stop the application with Ctrl-C in the same shell in which you executed the docker-compose up. If you stop the app this way, and attempt to restart it, you might get the following error:

web_1 | A server is already ​running.

  1. To resolve this, delete the file tmp/pids/server.pid (from within project folder), and then re-start the application with $ rm –Rf tmp/pids/server.pid $ docker-compose up

Restarting the Project for

1) To restart the project in the project directory first run:

$ docker-compose up

2) Restart the Database by using this command in a seperate terminal:

$ docker-compose run web rake db:create

Customizing the Development Setup

When you make changes to Either the Gemfile or docker-compose file to try out some different configurations or when developing new features, you must follow these steps.

Re-build Commands

1. Stop Containers
'$ docker-compose down'

2. Update Gem File

`$ docker-compose run web bundle install` (synchronizes changes in the **Gemfile.lock** to the host)

3. Rebuild With Updated Gemfile.

`$ docker-compose up --build`

When not introducing a new gem or making more subtle changes can simply run docker-compose up --build

Note : If you are passing any AWS access credentials, Please declare them in docker-compose.yml file as show in below

​environment:

 ​- AWS_ACCESS_KEY=#########

 ​- AWS_SECRET_KEY=##########
Clone this wiki locally