Easy to display hello world with Rails + Docker

I feel like I'm checking it every time I create an app, so I've summarized it as a memorandum. Please enter the app name in the app name section below.

Create a new directory ~ hello world !!

First, create a directory that will be the base of your app. In addition, use the touch command to create two empty files.

$mkdir app name&&cd app name
$ touch Gemfile Gemfile.lock

Because I'm developing using VScode It is started using the code command. By the way, the code command will start and create for you.

Edit the Gemfile.

$ code Gemfile

Gemfile


source 'https://rubygems.org'
gem 'rails', '~>5.2'

Create and edit a Dockerfile.

$ code Dockerfile

Dockerfile



FROM ruby:2.5
RUN apt-get update
RUN apt-get install -y \ 
    build-essential \
    libpq-dev \
    nodejs \
    postgresql-client \
    yarn \
    vim

WORKDIR /app name
COPY Gemfile Gemfile.lock /app name/
RUN bundle install

Create and edit the docker-compose.yml file.

$ code docker-compose.yml

docker-compose.yml


version: "3"

volumes:
  db-data:

services:
  web:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - ".:/app name"
    environment:
      - "DATABASE_PASSWORD=postgres"
    tty: true
    stdin_open: true
    depends_on:
      - db
    links:
      - db

  db:
    image: postgres
    volumes:
      - "db-data:/var/lib/postgresql/data"
    environment:
      - "POSTGRES_HOST_AUTH_METHOD=trust"
      - "POSTGRES_USER=postgres"
      - "POSTGRES_PASSWORD=postgres"

Start the container, enter the web container, and rails new.

$ docker-compose up --build -d
$ docker-compose exec web bash
$ rails new . --force --database=postgresql

Add to the database.yml file created by rails new.

database.yml


default: &default
  adapter: postgresql
  encoding: unicode
  host: db  #Postscript
  user: postgres  #Postscript
  port: 5432  #Postscript
  password: <%= ENV.fetch("DATABASE_PASSWORD") %>  #Postscript
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
$ rails db:migrate
$ rails s -b 0.0.0.0

If you access Chrome's search bar by typing localhost: 3000, you'll see hello world!

Recommended Posts

Easy to display hello world with Rails + Docker
Try to display hello world with spring + gradle
Hello World with Docker and C
[Rails] How to use rails console with docker
How to build Rails 6 environment with Docker
Rails deploy with Docker
Run JSP Hello World with Tomcat on Docker
[Rails] How to build an environment with Docker
Hello World with Micronaut
[Docker + Rails] How to deal with Rails server startup failure
[Vue Rails] "Hello Vue!" Displayed with Vue + Rails
Hello World with Spring Boot!
Run Rails whenever with docker
[Docker] Rails 5.2 environment construction with docker
Hello World with SpringBoot / Gradle
[Docker] Use whenever with Docker + Rails
Hello, World! With Asakusa Framework!
How to build Rails, Postgres, ElasticSearch development environment with Docker
Rails + MySQL environment construction with Docker
[rails] How to display db information
[Rails] Easy way to check columns
Build environment with vue.js + rails + docker
Until "Hello World" with Spring Boot
To display multiple lines with UILabel
Build Rails environment with Docker Compose
(Intellij) Hello World with Spring Boot
Hello World with GlassFish 5.1 + Servlet + JSP
Create PDF with itext7 ~ Hello World ~
[Environment construction with Docker] Rails 6 & MySQL 8
Connect to Rails server with iPhone
How to get along with Rails
"Hello world" for ImageJ with Eclipse
Introducing React to Rails with react-rails
Hello World with GWT 2.8.2 and Maven
Update MySQL from 5.7 to 8.0 with Docker
How to start Camunda with Docker
Super beginner builds Rails6 + Postgresql environment with Docker to the end
[Swift] Create a project with Xcode (ver 12.1) and display "Hello, World!"
How to install Pry after building Rails development environment with Docker
[Rails tutorial] Cannot deploy to Heroku/Change from hello, world to hola, mundo
How to build Rails + Vue + MySQL environment with Docker [2020/09 latest version]
How to share files with Docker Toolbox
Rails environment construction with Docker (personal apocalypse)
Easy deployment with Capistrano + AWS (EC2) + Rails
Building Rails 6 and PostgreSQL environment with Docker
Hello World with Eclipse + Spring Boot + Maven
Migrate existing Rails 6 apps to Docker environment
Hello world with Java template engine Thymeleaf
[Rails] How to display error messages individually
Introduced vscode with apt to docker: ubuntu
[Practice! ] Display Hello World in Spring Boot
Java development with Codenvy: Hello World! Run
[Rails API x Docker] Easy environment construction with shell & operation check with Flutter
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
"Hello, World!" With Kotlin + CLI in 5 minutes
Introduction to Ratpack (3) --hello world detailed explanation
Hello world with Kotlin and Tornado FX
Display API specifications with Laravel + SwaggerUI + Docker
How to display the text entered in text_area in Rails with line breaks
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
How Spring Security works with Hello World