Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails视图在Docker中渲染速度较慢_Ruby On Rails_Docker_Docker Compose - Fatal编程技术网

Ruby on rails Rails视图在Docker中渲染速度较慢

Ruby on rails Rails视图在Docker中渲染速度较慢,ruby-on-rails,docker,docker-compose,Ruby On Rails,Docker,Docker Compose,我正在对接一个Rails应用程序,我不知道为什么视图渲染得这么慢。在任意两个页面之间导航几乎需要2秒钟,有些页面需要更长的时间。在Docker之外运行应用程序时,不存在此问题 我正在使用Docker Desktop,其内存为16GB,容量为2015 MBP 这是我的Dockerfile: FROM ruby:2.5.3 # replace shell with bash so we can source files RUN rm /bin/sh && ln -s /bin/ba

我正在对接一个Rails应用程序,我不知道为什么视图渲染得这么慢。在任意两个页面之间导航几乎需要2秒钟,有些页面需要更长的时间。在Docker之外运行应用程序时,不存在此问题

我正在使用Docker Desktop,其内存为16GB,容量为2015 MBP

这是我的Dockerfile:

FROM ruby:2.5.3

# replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

RUN apt-get update -qq && apt-get install -y build-essential checkinstall \
    libpq-dev libvips-dev libvips-tools

# python dependencies
RUN apt-get install -y libreadline-gplv2-dev libncursesw5-dev libssl-dev \
    libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

WORKDIR /tmp
RUN wget https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs921/ghostscript-9.21.tar.gz && \
    tar xzf ghostscript-9.21.tar.gz && cd ghostscript-9.21 && \
    ./configure && make && make install

RUN wget https://nodejs.org/download/release/v10.8.0/node-v10.8.0.tar.gz && \
    tar xzf node-v10.8.0.tar.gz && cd node-v10.8.0 && \
    ./configure && make -j4 && make install

WORKDIR /app

RUN gem install bundler -v 1.17.3
RUN gem install foreman -v 0.85.0

RUN npm install -g yarn
这是我的docker-compose.yml:

version: "3"

services:
  web:
    build: 
      context: .
      dockerfile: Dockerfile
    command: bash -c "rm -f /app/tmp/pids/server.pid && foreman start -f Procfile.dev"
    volumes:
      - .:/app
      - npm_packages:/app/node_modules
      - bundler_gems:/usr/local/bundle/
    ports:
      - 3000:3000
      - 8888:8888
    depends_on:
      - postgres
      - redis
      - mailcatcher
    environment:
      PGHOST: postgres
      PGUSER: postgres
      PGPASSWORD: "password"
      RAILS_ENV: development
      RACK_ENV: development
      NODE_ENV: development

  mailcatcher:
    build:
      context: .
      dockerfile: Dockerfile
    command: bash -c "gem install mailcatcher && mailcatcher --ip 0.0.0.0 --foreground"
    volumes:
      - .:/app
      - npm_packages:/app/node_modules
      - bundler_gems:/usr/local/bundle/
    ports:
      - 1080:1080
      - 1025:1025

  redis:
    image: redis
    ports:
      - 6379
    volumes:
      - redis:/data

  postgres:
    image: postgres:9.6
    ports:
      - 54320:5432
    restart: always
    volumes:
      - postgres:/var/lib/postgresql/data

    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: "password"

volumes:
  postgres:
  redis:
  npm_packages:
  bundler_gems:
一切正常,只是速度很慢

duration=1623.74 view=1622.89

这可能是在Mac OS上运行docker compose的一个已知问题

尝试将行
127.0.0.1 localunixsocket.local
添加到文件
/etc/hosts


可在以下位置找到:

Docker for Mac中的绑定挂载是。如果删除所有
卷:
,应用程序是否运行得更好?(除了
/app
之外,这两个应用程序还有一个副作用,即防止Docker看到您安装的软件包的更新;您不希望在生产环境中看到任何更新。)我今天就试试这个。我不在生产中运行docker,所以这没有问题。当然,我很感谢你提供的信息。老实说,我的Dockerfile中有一些其他的东西,我没有挂载中的gems/modules,但后来我发现一篇博文,字面上说“所有其他示例都不好,这是一个真实用户的真实示例”,并展示了如何使用挂载。我只是在了解它…所以它的措辞似乎很权威。你能告诉我你推荐的处理Gemfile和package.json文件的方法吗?如果有“黄金之路”的话,我很想去。我发现这条路很有效。看来,
:cached
选项就是解决方案。不幸的是,它没有起到任何作用。谢谢你!