Hello
Rumor has it that modern development companies are definitely adopting this time.
Docker
I would like to introduce how to introduce (70% of memo elements for yourself)
First of all, I would like to explain about Docker. I've only dealt with Docker once, so what I'm talking about is To get acquainted with Docker, I recommend this article I will explain what Docker is like very carefully.
Find out about servers and the history of Docker's use.
First of all
Create a dockerfile
and use this kanji
FROM ruby:2.6 //Version specification command ruby-Confirm with v
RUN apt-get update -qq && \
apt-get install -y build-essential \
libpq-dev \
nodejs
RUN mkdir /Books app name
ENV APP_ROOT /Books
WORKDIR $APP_ROOT
ADD ./Gemfile $APP_ROOT/Gemfile
ADD ./Gemfile.lock $APP_ROOT/Gemfile.lock
RUN gem install bundler
RUN bundle install
ADD . $APP_ROOT
webpacker.yml
default: &default
source_path: app/javascript
source_entry_path: packs
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
check_yarn_integrity: false //*Caution
webpack_compile_output: true
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: []
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
# Extract and emit a css file
extract_css: false
static_assets_extensions:
- .jpg
- .jpeg
- .png
- .gif
- .tiff
- .ico
- .svg
- .eot
- .otf
- .ttf
- .woff
- .woff2
extensions:
- .mjs
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: true
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
check_yarn_integrity: false //*Caution
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
pretty: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: '**/node_modules/**'
test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Extract and emit a css file
extract_css: true
# Cache manifest.json for performance
cache_manifest: true
database.yml
default: &default
adapter: mysql2
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
password: example
# socket: /tmp/mysql.sock
host: db
development:
<<: *default
database: Books_development Your own database name (same below)
test:
<<: *default
database: Books_test
production:
<<: *default
database: Books_production
username: Books
password: <%= ENV['BOOKS_DATABASE_PASSWORD'] %>
username: root
password: <%= ENV['DATABASE_PASSWORD'] %>
socket: /var/lib/mysql/mysql.sock
docker-compose.yml
version: '3'
services:
db:
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: example //In my case, I didn't set it, so I decided to use it.
image: mysql
ports:
- "4306:3306"
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/Books
ports:
- "3000:3000"
depends_on:
- db
After writing,
% docker-compose build
Wait for a while while drinking a lot of milk and coffee milk.
% docker-compose run web bundle exec rake db:create
% docker-compose run web bundle exec rake db:migrate
If you can do it without problems
% docker-compose up
Launch the container to finish.
the end.
Finally, I would like to introduce some errors that appear as usual when launching.
web_1 | => Booting Puma
web_1 | => Rails 6.0.3.2 application starting in development
web_1 | => Run `rails server --help` for more startup options
web_1 | sh: 1: yarn: not found
web_1 |
web_1 |
web_1 | ========================================
web_1 | Your Yarn packages are out of date!
web_1 | Please run `yarn install --check-files` to update.
web_1 | ========================================
web_1 |
web_1 |
web_1 | To disable this check, please change `check_yarn_integrity`
web_1 | to `false` in your webpacker config file (config/webpacker.yml).
web_1 |
web_1 |
web_1 |
web_1 |
web_1 |
web_1 | Exiting
books_web_1 exited with code 1
As you can see if you read this error calm down,
% yarn install --check-files
or
% yarn update
Or
I introduced it earlier.
I think that if you do these things, it will be cured.
I'm a complete beginner, so I'm going to study Docker again.
This time
that's all.
Reference article (Rather almost the same) [Introduce Docker with MySQL to the existing rails6 app. ](Https://qiita.com/momokan928/items/d560fff3855fcbe0b811#1dockerfiledocker-composeyml%E3%82%92%E6%97%A2%E5%AD%98%E3%82%A2%E3%83%97% E3% 83% AA% E3% 81% AE% E3% 83% AB% E3% 83% BC% E3% 83% 88% E3% 83% 87% E3% 82% A3% E3% 83% AC% E3% 82% AF% E3% 83% 88% E3% 83% AA% E3% 81% AB% E4% BD% 9C% E6% 88% 90% E3% 81% 99% E3% 82% 8B) Introduction to Docker
Recommended Posts