Very simple set of files to help bootstrap a rails app in docker using postgres so that the docker evironment doesn't need to be installed on you machine -- eliminating conflicting version management and other nasties.
This repository is optimized for working on a Windows OS. Adapted from docker.com instructions here
Make sure that you have docker
and docker-compose
installed on your machine.
clone into directory name of your choice git clone https://github.com/beartums/docker-rails-stub.git <directoryname>
. CD to that directory and build:
docker-compose build
Create your application with:
docker-compose run web rails new . --force --no-deps --database=postgresql
This should populate your folder with all the files needed to run a rails app. We're almost there!
Edit your gemfile and replace gem 'sass-rails', '~> 5.0'
with gem 'sassc-rails'
run
docker-compose build
Now you need to edit the config/database.yml
file to be able to connect to the
database. Copy the uncommented lines from /db.yml.example
create the database for rails with
docker-compose run web rake db:create
start the server: docker-compose up
Browse to localhost:3000. You should see the rails place holder. YAY!
NOTE:
-
If you make any changes to the gemfile, you will need to run
docker-compose build
ordocker-compose up --build
for your installation to save the changes -
You can add dependencies using yarn, but only in a running container. Once you have the container running (
docker-compose up
) open another terminal in the same folder and rundocker exec -it <folder>_web_1 /bin/bash
to open a terminal in the running container. you can run yarn from this command line , as well as rails c, or any other command you need to run for debugging and development
- docker-compose stop
- Stop the running containers
- docker-compose down
- Stop and remove the running containers
- docker-compose up --build
- Build the containers before starting them
- docker-compose run web bundle install
- Run the gem bundler. (replace `bundle install` with any other one-off command)
- *docker exec -it <folderName>_web_1 /bin/bash*
- Open a bash prompt in the container hosting the server. This is probably the most important command. From here you can run any useful commands in the rails environment, like `rails console`, `yarn install --check-files`, `yarn add ...` etc. You *must* update your rails environment here, rather than at your windows terminal
more to come...