[RUBY] About the case where "Docker" freeter tried to put Docker in the existing Rails application


Rumor has it that modern development companies are definitely adopting this time.


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 \        

RUN mkdir /Books app name


ADD ./Gemfile $APP_ROOT/Gemfile
ADD ./Gemfile.lock $APP_ROOT/Gemfile.lock

RUN gem install bundler 
RUN bundle install


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

    - .jpg
    - .jpeg
    - .png
    - .gif
    - .tiff
    - .ico
    - .svg
    - .eot
    - .otf
    - .ttf
    - .woff
    - .woff2

    - .mjs
    - .js
    - .sass
    - .scss
    - .css
    - .module.sass
    - .module.scss
    - .module.css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

  <<: *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/
    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
      'Access-Control-Allow-Origin': '*'
      ignored: '**/node_modules/**'

  <<: *default
  compile: true

  # Compile test packs to a separate directory
  public_output_path: packs-test

  <<: *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


default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root  
  password: example
  # socket: /tmp/mysql.sock

  host: db

  <<: *default
  database: Books_development Your own database name (same below)

  <<: *default
  database: Books_test

  <<: *default
  database: Books_production
  username: Books
  password: <%= ENV['BOOKS_DATABASE_PASSWORD'] %>
  username: root
  password: <%= ENV['DATABASE_PASSWORD'] %>
  socket: /var/lib/mysql/mysql.sock


version: '3'
    command: --default-authentication-plugin=mysql_native_password
    restart: always
      MYSQL_ROOT_PASSWORD: example  //In my case, I didn't set it, so I decided to use it.
    image: mysql
      - "4306:3306"

    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b ''"
      - .:/Books
      - "3000:3000"
      - db

After writing,

% docker-compose build 

Wait for a while while drinking a lot of milk and coffee milk.

If I can
% 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 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
% yarn update


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

About the case where "Docker" freeter tried to put Docker in the existing Rails application
Rails6 I tried to introduce Docker to an existing application
How to install Docker in the local environment of an existing Rails application [Rails 6 / MySQL 8]
I tried to organize the session in Rails
about the where method (rails)
About the symbol <%%> in Rails erb
[Rails] I tried deleting the application
I tried to sort the data in descending order, ascending order / Rails
[Rails] Talk about paying attention to the return value of where
I tried to make the "Select File" button of the sample application created in the Rails tutorial cool
After learning Progate, I tried to make an SNS application using Rails in the local environment
[rails] The case where the server stopped working
Migrate existing Rails 6 apps to Docker environment
I tried to build a Firebase application development environment with Docker in 2020
Introduce Docker to the development environment and test environment of existing Rails and MySQL applications
[Rails] How to operate the helper method used in the main application with Administrate
Introduce docker to the application you are creating
How to check Rails commands in the terminal
How to set the display time to Japan time in Rails
I tried to organize the cases used in programming
Implement post search function in Rails application (where method)
I tried to summarize the state transition of docker
I tried installing the Docker Integration plugin in IntelliJ
SSL in the local environment of Docker / Rails / puma
I tried to implement the Euclidean algorithm in Java
[Rails] How to display an image in the view
[Rails 6.0, Docker] I tried to summarize the Docker environment construction and commands necessary to create a portfolio
I tried to develop the cache function of Application Container Cloud Service in the local environment
What to do when Rails on Docker does not reflect controller changes in the browser
About rails application server
I tried to make an application in 3 months from inexperienced
I tried to introduce Bootstrap 4 to the Rails 6 app [for beginners]
How to disable existing selected items in the select box
I tried to implement a buggy web application in Kotlin
[Rails] How to display information stored in the database in view
[Docker] How to back up and restore the DB data of Rails application on docker-compose [MySQL]