GithubHelp home page GithubHelp logo

merouaneamqor / dockerized_rails_app Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ayesha54/dockerized_rails_app

0.0 0.0 0.0 29 KB

Dockerized Ruby on Rails 5 Application

Shell 0.65% JavaScript 3.85% Ruby 73.34% CSS 2.31% HTML 18.38% Dockerfile 1.47%

dockerized_rails_app's Introduction

Dockerize New Rails5 Application

Start by setting up the application needed to build the app by using docker-compose. The app will run inside a Docker container containing its dependencies. Defining dependencies is done using a file called Dockerfile.

docker-compose build

Connect the database

Replace the contents of config/database.yml with the following:

 default: &default
  adapter: postgresql
  encoding: unicode
  host: db
  username: postgres
  password:
  pool: 5
development:
  <<: *default
  database: myapp_development
test:
  <<: *default
  database: myapp_test 

You can now boot the app with docker-compose up:

docker-compose up 

If all’s well, you should see some PostgreSQL output.

Finally, you need to create the database. In another terminal, run:

docker-compose run web rake db:create

View the Rails welcome page!

That’s it. Your app should now be running on port 3001 on your Docker daemon. On Docker Desktop for Mac and Docker Desktop for Windows, go to http://localhost:3001 on a web browser to see the Rails Welcome. Now, you can play with the rails application within a container or can develop a whole application by using docker-compose run web as a prefix command.

for eg: docker-compose run web rail c

Above command will take you in the rails console OR you can get into the container itself by running following commands:

docker ps # this command will show the running container 

copy the container id and run following command:

docker exec -it <container id> bash 

This will take you in the container. Now you can work with rails by running any rails commands. for example: rails console to exit the container without stopping it :

ctrl+q 

To stop the application, run

docker-compose down 

in your project directory.

Restart the application To restart the application run docker-compose up in the project directory as you don’t need to rebuild the docker-compose. Rebuild the application

If you make changes to the Gemfile or the Compose file to try out some different configurations, you need to rebuild. Some changes require only docker-compose up --build, but a full rebuild requires a re-run of docker-compose run web bundle install to sync changes in the Gemfile.lock to the host, followed by docker-compose up --build. Here is an example of the first case, where a full rebuild is not necessary. Suppose you simply want to change the exposed port on the localhost from 3000 in our first example to 3001. Make the change to the Compose file to expose port 3000 on the container through a new port, 3001, on the host, and save the changes: ports: - "3001:3000"

Now, rebuild and restart the app with

docker-compose up --build 

Inside the container, your app is running on the same port as before, but the Rails Welcome is now available on your localhost.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.