[Rails] How to speed up docker-compose

Development environment

・ Docker: 19.03.8 -Docker-Compose: 1.25.5 ・ Ruby: 2.5.7 Rails: 5.2.4 ・ Vagrant: 2.2.7 -VirtualBox: 6.1 ・ OS: macOS Catalina

Premise

The following has been implemented.

-How to build an environment with Docker

Cause

When docker-compose is executed, extra files such as temp, log, vendor, and .git are mounted.

Solution

Overwrite the mount of the directory that does not need to be mounted with another volume.

Edit docker-compose.yml

docker-compose.yml


#Change before
version: '3'
services:
  db:
    image: postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: password
  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

#After change
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:
      - .:/app:cached
      - /app/vendor
      - /app/tmp
      - /app/log
      - /app/.git
    ports:
      - '3000:3000'
    depends_on:
      - db

Recommended Posts

[Rails] How to speed up docker-compose
How to write Rails
How to uninstall Rails
How to write docker-compose
How to create docker-compose
[rails] How to post images
[Rails] How to use enum
[Rails] How to use enum
How to read rails routes
How to use rails join
How to terminate rails server
How to write Rails seed
[Rails] How to use validation
[Rails] How to disable turbolinks
[Rails] How to use authenticate_user!
[Rails] How to implement scraping
[Rails] How to make seed
How to write Rails routing
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
[Rails] How to use Scope
[Rails] How to use gem "devise"
[Rails] How to use devise (Note)
[Rails] How to use flash messages
[rails] How to display db information
[Rails] How to prevent screen transition
How to use Ruby on Rails
How to deploy Bootstrap on Rails
[Rails] How to add new pages
[Rails] How to write exception handling?
[Rails] How to install ImageMagick (RMajick)
[Rails] How to install Font Awesome
[Rails] How to use Active Storage
How to introduce jQuery in Rails 6
[Rails] How to implement star rating
[Introduction to Rails] How to use render
How to install Swiper in Rails
[Note] How to restart the Windows container set up with docker-compose
How to change app name in rails
[Rails] How to convert from erb to haml
[Rails] How to upload images using Carrierwave
How to insert a video in Rails
[Rails] How to use ActiveRecord :: Bitemporal (BiTemporalDataModel)
[Rails] How to use the map method
[Rails] How to display error messages individually
How to use MySQL in Rails tutorial
How to resolve errors when installing Rails 5.1.3
How to set up and use kapt
[rails] How to configure routing in resources
[Ruby on Rails] How to use redirect_to
[rails] How to create a partial template
[Rails 5.x] How to introduce free fonts
How to implement ranking functionality in Rails
[Note] How to use Rails 6 Devise + cancancan
How to monitor nginx with docker-compose with datadog
How to implement image posting using rails
[Rails] How to use video_tag to display videos
[Rails] How to use helper method, confimartion
How to use credentials.yml.enc introduced in Rails 5.2
[Rails] How to translate devise into Japanese
How to build Rails 6 environment with Docker