Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.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 Docker使用Rails设置时出错_Ruby On Rails_Docker - Fatal编程技术网

Ruby on rails Docker使用Rails设置时出错

Ruby on rails Docker使用Rails设置时出错,ruby-on-rails,docker,Ruby On Rails,Docker,因此,我正在使用postgresql数据库创建一个最小的rails应用程序。我想确保rails应用程序正常工作,并确保docker和您的rails应用程序尽可能相似 以下是我的Dockerfile内容: FROM ruby:latest RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs RUN mkdir /rails_docker WORKDIR /rails_docker

因此,我正在使用postgresql数据库创建一个最小的rails应用程序。我想确保rails应用程序正常工作,并确保docker和您的rails应用程序尽可能相似

以下是我的Dockerfile内容:

FROM ruby:latest
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /rails_docker
WORKDIR /rails_docker
COPY Gemfile /rails_docker/Gemfile
COPY Gemfile.lock /rails_docker/Gemfile.lock
RUN bundle install
COPY . /rails_docker
version: '3'
services: 
  db:
    image: postgres
    restart: always
    environment: 
        POSTGRES_USER: 'samnorton'
        POSTGRES_PASSWORD: 'grace0512'
    volumes: 
        - postgres-data:/var/lib/postgresql/data
    ports: 
        - '9999:5432'
  web: 
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
        - .:/rails_docker
    ports:
        - "3000:3000"
    depends_on:
        - db
volumes:
  postgres-data:
    driver: local
下面是我的docker-compose.yml文件内容:

FROM ruby:latest
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /rails_docker
WORKDIR /rails_docker
COPY Gemfile /rails_docker/Gemfile
COPY Gemfile.lock /rails_docker/Gemfile.lock
RUN bundle install
COPY . /rails_docker
version: '3'
services: 
  db:
    image: postgres
    restart: always
    environment: 
        POSTGRES_USER: 'samnorton'
        POSTGRES_PASSWORD: 'grace0512'
    volumes: 
        - postgres-data:/var/lib/postgresql/data
    ports: 
        - '9999:5432'
  web: 
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
        - .:/rails_docker
    ports:
        - "3000:3000"
    depends_on:
        - db
volumes:
  postgres-data:
    driver: local
我还设置了一个最小的Gemfile和Gemfile锁。当我运行
sudo docker compose up
时,我在ff错误中运行:

data-K54C:~/Desktop/rails_docker$ sudo docker-compose up
[sudo] password for sam: 
railsdocker_db_1 is up-to-date
Starting railsdocker_web_1 ... 
Starting railsdocker_web_1 ... done
Attaching to railsdocker_db_1, railsdocker_web_1
db_1   | 2019-12-12 14:20:38.333 UTC [1] LOG:  starting PostgreSQL 12.0 (Debian 12.0-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2019-12-12 14:20:38.342 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2019-12-12 14:20:38.342 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2019-12-12 14:20:38.411 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2019-12-12 14:20:38.547 UTC [25] LOG:  database system was shut down at 2019-12-12 14:20:06 UTC
db_1   | 2019-12-12 14:20:38.609 UTC [1] LOG:  database system is ready to accept connections
db_1   | 2019-12-12 14:24:47.800 UTC [1] LOG:  received smart shutdown request
db_1   | 2019-12-12 14:24:47.841 UTC [1] LOG:  background worker "logical replication launcher" (PID 31) exited with exit code 1
db_1   | 2019-12-12 14:24:47.844 UTC [26] LOG:  shutting down
db_1   | 2019-12-12 14:24:48.094 UTC [1] LOG:  database system is shut down
db_1   | 2019-12-12 15:54:38.528 UTC [1] LOG:  starting PostgreSQL 12.0 (Debian 12.0-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2019-12-12 15:54:38.543 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2019-12-12 15:54:38.543 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2019-12-12 15:54:38.627 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2019-12-12 15:54:38.806 UTC [23] LOG:  database system was shut down at 2019-12-12 14:24:48 UTC
db_1   | 2019-12-12 15:54:39.053 UTC [1] LOG:  database system is ready to accept connections
db_1   | 2019-12-12 16:40:42.473 UTC [1] LOG:  received smart shutdown request
db_1   | 2019-12-12 16:40:42.590 UTC [1] LOG:  background worker "logical replication launcher" (PID 29) exited with exit code 1
db_1   | 2019-12-12 16:40:42.590 UTC [24] LOG:  shutting down
db_1   | 2019-12-12 16:40:43.398 UTC [1] LOG:  database system is shut down
db_1   | 2019-12-13 00:02:44.643 UTC [1] LOG:  starting PostgreSQL 12.0 (Debian 12.0-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2019-12-13 00:02:44.665 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2019-12-13 00:02:44.665 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2019-12-13 00:02:44.751 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2019-12-13 00:02:44.947 UTC [23] LOG:  database system was shut down at 2019-12-12 16:40:43 UTC
db_1   | 2019-12-13 00:02:45.179 UTC [1] LOG:  database system is ready to accept connections
db_1   | 2019-12-13 00:32:00.742 UTC [1] LOG:  received smart shutdown request
db_1   | 2019-12-13 00:32:01.089 UTC [1] LOG:  background worker "logical replication launcher" (PID 29) exited with exit code 1
db_1   | 2019-12-13 00:32:01.089 UTC [24] LOG:  shutting down
db_1   | 2019-12-13 00:32:02.353 UTC [1] LOG:  database system is shut down
db_1   | 2019-12-13 01:01:34.874 UTC [1] LOG:  starting PostgreSQL 12.0 (Debian 12.0-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2019-12-13 01:01:34.896 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2019-12-13 01:01:34.896 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2019-12-13 01:01:35.035 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2019-12-13 01:01:35.479 UTC [23] LOG:  database system was shut down at 2019-12-13 00:32:01 UTC
db_1   | 2019-12-13 01:01:35.873 UTC [1] LOG:  database system is ready to accept connections
web_1  | Usage:
web_1  |   rails new APP_PATH [options]
web_1  | 
web_1  | Options:
web_1  |       [--skip-namespace], [--no-skip-namespace]            # Skip namespace (affects only isolated applications)
web_1  |   -r, [--ruby=PATH]                                        # Path to the Ruby binary of your choice
web_1  |                                                            # Default: /usr/local/bin/ruby
web_1  |   -m, [--template=TEMPLATE]                                # Path to some application template (can be a filesystem path or URL)
web_1  |   -d, [--database=DATABASE]                                # Preconfigure for selected database (options: mysql/postgresql/sqlite3/oracle/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
web_1  |                                                            # Default: sqlite3
web_1  |       [--skip-yarn], [--no-skip-yarn]                      # Don't use Yarn for managing JavaScript dependencies
web_1  |       [--skip-gemfile], [--no-skip-gemfile]                # Don't create a Gemfile
web_1  |   -G, [--skip-git], [--no-skip-git]                        # Skip .gitignore file
web_1  |       [--skip-keeps], [--no-skip-keeps]                    # Skip source control .keep files
web_1  |   -M, [--skip-action-mailer], [--no-skip-action-mailer]    # Skip Action Mailer files
web_1  |   -O, [--skip-active-record], [--no-skip-active-record]    # Skip Active Record files
web_1  |       [--skip-active-storage], [--no-skip-active-storage]  # Skip Active Storage files
web_1  |   -P, [--skip-puma], [--no-skip-puma]                      # Skip Puma related files
web_1  |   -C, [--skip-action-cable], [--no-skip-action-cable]      # Skip Action Cable files
web_1  |   -S, [--skip-sprockets], [--no-skip-sprockets]            # Skip Sprockets files
web_1  |       [--skip-spring], [--no-skip-spring]                  # Don't install Spring application preloader
web_1  |       [--skip-listen], [--no-skip-listen]                  # Don't generate configuration that depends on the listen gem
web_1  |       [--skip-coffee], [--no-skip-coffee]                  # Don't use CoffeeScript
web_1  |   -J, [--skip-javascript], [--no-skip-javascript]          # Skip JavaScript files
web_1  |       [--skip-turbolinks], [--no-skip-turbolinks]          # Skip turbolinks gem
web_1  |   -T, [--skip-test], [--no-skip-test]                      # Skip test files
web_1  |       [--skip-system-test], [--no-skip-system-test]        # Skip system test files
web_1  |       [--skip-bootsnap], [--no-skip-bootsnap]              # Skip bootsnap gem
web_1  |       [--dev], [--no-dev]                                  # Setup the application with Gemfile pointing to your Rails checkout
web_1  |       [--edge], [--no-edge]                                # Setup the application with Gemfile pointing to Rails repository
web_1  |       [--rc=RC]                                            # Path to file containing extra configuration options for rails command
web_1  |       [--no-rc], [--no-no-rc]                              # Skip loading of extra configuration options from .railsrc file
web_1  |       [--api], [--no-api]                                  # Preconfigure smaller stack for API only apps
web_1  |   -B, [--skip-bundle], [--no-skip-bundle]                  # Don't run bundle install
web_1  |       [--webpack=WEBPACK]                                  # Preconfigure for app-like JavaScript with Webpack (options: react/vue/angular/elm/stimulus)
web_1  | 
web_1  | Runtime options:
web_1  |   -f, [--force]                    # Overwrite files that already exist
web_1  |   -p, [--pretend], [--no-pretend]  # Run but do not make any changes
web_1  |   -q, [--quiet], [--no-quiet]      # Suppress status output
web_1  |   -s, [--skip], [--no-skip]        # Skip files that already exist
web_1  | 
web_1  | Rails options:
web_1  |   -h, [--help], [--no-help]        # Show this help message and quit
web_1  |   -v, [--version], [--no-version]  # Show Rails version number and quit
web_1  | 
web_1  | Description:
web_1  |     The 'rails new' command creates a new Rails application with a default
web_1  |     directory structure and configuration at the path you specify.
web_1  | 
web_1  |     You can specify extra command-line arguments to be used every time
web_1  |     'rails new' runs in the .railsrc configuration file in your home directory.
web_1  | 
web_1  |     Note that the arguments specified in the .railsrc file don't affect the
web_1  |     defaults values shown above in this help message.
web_1  | 
web_1  | Example:
web_1  |     rails new ~/Code/Ruby/weblog
web_1  | 
web_1  |     This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
railsdocker_web_1 exited with code 0
in the the curent case you are not using the right rails directory i think
我不确定我是否做得对,我想知道这是我设置的WORKDIR还是端口3000上正在运行的东西。知道我的设置有什么问题吗

更新:

运行
sudo docker compose build
sudo docker compose up
后,我发现以下错误:

data-K54C:~/Desktop/rails_docker$ sudo docker-compose up
railsdocker_db_1 is up-to-date
Recreating railsdocker_web_1 ... 
Recreating railsdocker_web_1 ... error

ERROR: for railsdocker_web_1  no such image: sha256:6d066f5f04e34f6f442d4a68fb4124e1093bb6a976593087d5ebc92478abfaae: No such image: sha256:6d066f5f04e34f6f442d4a68fb4124e1093bb6a976593087d5ebc92478abfaae

ERROR: for web  no such image: sha256:6d066f5f04e34f6f442d4a68fb4124e1093bb6a976593087d5ebc92478abfaae: No such image: sha256:6d066f5f04e34f6f442d4a68fb4124e1093bb6a976593087d5ebc92478abfaae
ERROR: Encountered errors while bringing up the project.
sam@sam-K54C:~/Desktop/rails_docker$ clear

尝试按以下方式替换
命令

command: bundle exec bin/rails s -p 3000 -b '0.0.0.0'

那应该行。

你做过docker compose构建吗?似乎找不到railstry docker compose ps以查看是否有任何旧图像如果有任何旧图像,请将其删除docker rm并重试