I made a development environment with rails6 + docker + postgreSQL + Materialize.

Rails environment construction

Docker3 Rails6.0.3 Ruby2.7.0 DB:PostgeSQL I will create it in this environment.

1. Launch docker

I referred to @ shungo_m's "How to build Rails 6 environment with Docker".

Creating files required to launch docker

$ mkdir myapp
$ cd myapp
$ touch Dockerfile
$ touch docker-compose.yml
$ touch entrypoint.sh
$ touch Gemfile
$ touch Gemfile.lock

Dokerfile


FROM ruby:2.7.0
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client

RUN apt-get update && apt-get install -y curl apt-transport-https wget && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y yarn

RUN curl -sL https://deb.nodesource.com/setup_7.x | bash - && \
apt-get install nodejs

RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

CMD ["rails", "server", "-b", "0.0.0.0"]

docker-compose.yml


version: '3'
services:
  db:
    image: postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
    environment:
      POSTGRES_HOST_AUTH_METHOD: 'trust'


  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/myapp
    ports:
      - "3000:3000"
    depends_on:
      - db

entrypoint.sh


#!/bin/bash
set -e

# Remove a potentially pre-existing server.pid for Rails.
rm -f /myapp/tmp/pids/server.pid

# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "[email protected]"

Gemfile


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

Gemfile.lock



Now that you have created the necessary files, create a project with rails new.

$ docker-compose run web rails new . --force --no-deps --database=postgresql --skip-bundle

If you proceed with docker build and up as it is, you will be asked to install webpacker, so install it.

$ docker-compose run web bundle exec rails webpacker:install

After that, set the DB and complete the docker environment.

2. Introduction of Materia rize

I referred to this site. https://monaga.site/use-materialize-in-rails6/

$ docker-compose run web yarn add materialize-css

Create and describe a file called application_style.js in app / javascript / packs.

application_style.js


import "../stylesheets/application.scss";;

Create and write a application.scss file in the app / javascript / stylesheets directory. ..

application.scss


@import "materialize-css/dist/css/materialize.min.css";

Finally, add the code required to load javascript to app / javascript / packs / application.js.

application.js


import "materialize-css/dist/js/materialize.min.js";
M.AutoInit();

This completes the environment construction.

There are many samples on the official page of materialize, so please refer to them. https://materializecss.com/

reference

https://materializecss.com/ https://monaga.site/use-materialize-in-rails6/ https://qiita.com/shungo_m/items/fd1ab99fbe76d39e456c

Recommended Posts

I made a development environment with rails6 + docker + postgreSQL + Materialize.
Build a development environment for Docker + Rails6 + Postgresql
Build a local development environment for Rails tutorials with Docker (Rails 6 + PostgreSQL + Webpack)
I tried to create a padrino development environment with Docker
Building Rails 6 and PostgreSQL environment with Docker
Build a PureScript development environment with Docker
Build a Wordpress development environment with Docker
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
Build a WordPress development environment quickly with Docker
I made a LINE bot with Rails + heroku
Create a Spring Boot development environment with docker
I made a portfolio with Ruby On Rails
I built a rails environment with docker and mysql, but I got stuck
I tried to build a Firebase application development environment with Docker in 2020
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
Template: Build a Ruby / Rails development environment with a Docker container (Ubuntu version)
Template: Build a Ruby / Rails development environment with a Docker container (Mac version)
[Docker] Rails 5.2 environment construction with docker
Rails + MySQL environment construction with Docker
Create a Vue3 environment with Docker!
I tried to create a java8 development environment with Chocolatey
Build a Node.js environment with Docker
[Rails] [Docker] Copy and paste is OK! How to build a Rails development environment with Docker
I made a GUI with Swing
Build environment with vue.js + rails + docker
Build Rails environment with Docker Compose
Rails application development environment construction with Docker [Docker, Rails, Puma, Nginx, MySQL]
How to build Rails, Postgres, ElasticSearch development environment with Docker
[Environment construction with Docker] Rails 6 & MySQL 8
Create Rails5 and postgresql environment with Docker and make pgadmin available
[Rails] I made a simple calendar mini app with customized specifications.
Ruby on Rails development environment construction with Docker + VSCode (Remote Container)
Super beginner builds Rails6 + Postgresql environment with Docker to the end
How to install Pry after building Rails development environment with Docker
PostgreSQL environment construction with Docker (from setup to just before development)
Build a development environment for Django + MySQL + nginx with Docker Compose
Steps to build a Ruby on Rails development environment with Vagrant
Rails environment construction with Docker (personal apocalypse)
Laravel development environment construction with Docker (Mac)
Create Rails 6 + MySQL environment with Docker compose
Create a MySQL environment with Docker from 0-> 1
Create Spring Boot-gradle-mysql development environment with Docker
[Docker] Development environment construction Rails6 / Ruby2.7 / MySQL8
I made a risky die with Ruby
I made a rock-paper-scissors app with kotlin
I made a rock-paper-scissors app with android
Lightweight PHP 7.4 development environment created with Docker
I made a bulletin board using Docker 1
How to build Rails 6 environment with Docker
Build a simple Docker + Django development environment
Build debug environment on container --Build local development environment for Rails tutorial with Docker-
Creating a java web application development environment with docker for mac part1
[Copy and paste] Build a Laravel development environment with Docker Compose Part 2
[Copy and paste] Build a Laravel development environment with Docker Compose Participation
Create a java web application development environment with docker for mac part2
Let's get started with Java-Create a development environment ①
[Memo] Create a CentOS 8 environment easily with Docker
[Rails] rails new to create a database with PostgreSQL
04. I made a front end with SpringBoot + Thymeleaf
Build a Laravel / Docker environment with VSCode devcontainer