Docker3 Rails6.0.3 Ruby2.7.0 DB:PostgeSQL I will create it in this environment.
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 "$@"
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.
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/
https://materializecss.com/ https://monaga.site/use-materialize-in-rails6/ https://qiita.com/shungo_m/items/fd1ab99fbe76d39e456c
Recommended Posts