如何在 docker 环境中安装 yarn?

How can I install yarn on the docker environment?

现在,我正在尝试为 docker 上的 rails 上的 Ruby 创建环境。 我阅读了一些人写的文档和一些博客并尝试过。 但是我遇到了错误,无法完成。

看来我必须在docker环境中安装yarn,但我不知道我是否安装正确。

有知道的请告诉我

到目前为止我写的是这样的。

Docker 文件

FROM ruby:3.0.2
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client


RUN mkdir /docker-test2
WORKDIR /docker-test2
COPY Gemfile /docker-test2/Gemfile
COPY Gemfile.lock /docker-test2/Gemfile.lock
RUN bundle install
COPY . /docker-test2


# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]

docker-compose.yml

version: "3.9"
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:
      - .:/docker-test2
    ports:
      - "3000:3000"
    depends_on:
      - db

entrypoint.sh

#!/bin/bash
set -e

# Remove a potentially pre-existing server.pid for Rails.
rm -f /docker-test2/tmp/pids/server.pid

# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"

当我尝试 docker-compose run 时,错误提示是这样的。

    Attaching to docker-test2_db_1, docker-test2_web_1
db_1   | The files belonging to this database system will be owned by user "postgres".
db_1   | This user must also own the server process.
db_1   | 
db_1   | The database cluster will be initialized with locale "en_US.utf8".
db_1   | The default database encoding has accordingly been set to "UTF8".
db_1   | The default text search configuration will be set to "english".
db_1   | 
db_1   | Data page checksums are disabled.
db_1   | 
db_1   | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db_1   | creating subdirectories ... ok
db_1   | selecting dynamic shared memory implementation ... posix
db_1   | selecting default max_connections ... 100
db_1   | selecting default shared_buffers ... 128MB
db_1   | selecting default time zone ... Etc/UTC
db_1   | creating configuration files ... ok
db_1   | running bootstrap script ... ok
db_1   | performing post-bootstrap initialization ... ok
db_1   | syncing data to disk ... ok
db_1   | 
db_1   | 
db_1   | Success. You can now start the database server using:
db_1   | initdb: warning: enabling "trust" authentication for local connections
db_1   | You can change this by editing pg_hba.conf or using the option -A, or
db_1   | --auth-local and --auth-host, the next time you run initdb.
db_1   | 
db_1   |     pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1   | 
db_1   | waiting for server to start....2021-08-30 09:03:01.284 UTC [47] LOG:  starting PostgreSQL 13.4 (Debian 13.4-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2021-08-30 09:03:01.285 UTC [47] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2021-08-30 09:03:01.299 UTC [48] LOG:  database system was shut down at 2021-08-30 09:02:59 UTC
db_1   | 2021-08-30 09:03:01.322 UTC [47] LOG:  database system is ready to accept connections
db_1   |  done
db_1   | server started
db_1   | 
db_1   | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1   | 
db_1   | 2021-08-30 09:03:01.497 UTC [47] LOG:  received fast shutdown request
db_1   | waiting for server to shut down....2021-08-30 09:03:01.498 UTC [47] LOG:  aborting any active transactions
db_1   | 2021-08-30 09:03:01.500 UTC [47] LOG:  background worker "logical replication launcher" (PID 54) exited with exit code 1
db_1   | 2021-08-30 09:03:01.500 UTC [49] LOG:  shutting down
db_1   | 2021-08-30 09:03:01.544 UTC [47] LOG:  database system is shut down
db_1   |  done
db_1   | server stopped
db_1   | 
db_1   | PostgreSQL init process complete; ready for start up.
db_1   | 
db_1   | 2021-08-30 09:03:01.627 UTC [1] LOG:  starting PostgreSQL 13.4 (Debian 13.4-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2021-08-30 09:03:01.627 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2021-08-30 09:03:01.627 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2021-08-30 09:03:01.631 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2021-08-30 09:03:01.652 UTC [66] LOG:  database system was shut down at 2021-08-30 09:03:01 UTC
db_1   | 2021-08-30 09:03:01.671 UTC [1] LOG:  database system is ready to accept connections
db_1   | 
db_1   | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1   | 
db_1   | 2021-08-30 09:04:33.607 UTC [1] LOG:  starting PostgreSQL 13.4 (Debian 13.4-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2021-08-30 09:04:33.607 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2021-08-30 09:04:33.607 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2021-08-30 09:04:33.611 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2021-08-30 09:04:33.659 UTC [27] LOG:  database system was interrupted; last known up at 2021-08-30 09:03:01 UTC
db_1   | 2021-08-30 09:04:34.659 UTC [27] LOG:  database system was not properly shut down; automatic recovery in progress
db_1   | 2021-08-30 09:04:34.676 UTC [27] LOG:  redo starts at 0/15C6DD8
db_1   | 2021-08-30 09:04:34.676 UTC [27] LOG:  invalid record length at 0/15C6E10: wanted 24, got 0
db_1   | 2021-08-30 09:04:34.676 UTC [27] LOG:  redo done at 0/15C6DD8
db_1   | 2021-08-30 09:04:34.694 UTC [1] LOG:  database system is ready to accept connections
db_1   | 
db_1   | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1   | 
db_1   | 2021-08-30 09:11:48.053 UTC [1] LOG:  starting PostgreSQL 13.4 (Debian 13.4-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2021-08-30 09:11:48.053 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2021-08-30 09:11:48.053 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2021-08-30 09:11:48.056 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2021-08-30 09:11:48.105 UTC [27] LOG:  database system was interrupted; last known up at 2021-08-30 09:04:34 UTC
db_1   | 2021-08-30 09:11:49.433 UTC [27] LOG:  database system was not properly shut down; automatic recovery in progress
db_1   | 2021-08-30 09:11:49.436 UTC [27] LOG:  redo starts at 0/15C6E88
db_1   | 2021-08-30 09:11:49.436 UTC [27] LOG:  invalid record length at 0/15C6EC0: wanted 24, got 0
db_1   | 2021-08-30 09:11:49.436 UTC [27] LOG:  redo done at 0/15C6E88
db_1   | 2021-08-30 09:11:49.454 UTC [1] LOG:  database system is ready to accept connections
web_1  | => Booting Puma
web_1  | => Rails 6.1.4.1 application starting in development 
web_1  | => Run `bin/rails server --help` for more startup options
web_1  | Exiting
web_1  | /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/configuration.rb:103:in `rescue in load': Webpacker configuration file not found /docker-test2/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /docker-test2/config/webpacker.yml (RuntimeError)
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/configuration.rb:95:in `load'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/configuration.rb:92:in `data'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/configuration.rb:88:in `fetch'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/configuration.rb:43:in `public_path'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/configuration.rb:47:in `public_output_path'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/configuration.rb:51:in `public_manifest_path'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/manifest.rb:83:in `load'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/manifest.rb:18:in `refresh'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/commands.rb:47:in `bootstrap'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker.rb:35:in `bootstrap'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/railtie.rb:41:in `block in <class:Engine>'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/initializable.rb:32:in `instance_exec'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/initializable.rb:32:in `run'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/initializable.rb:61:in `block in run_initializers'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:228:in `block in tsort_each'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:431:in `each_strongly_connected_component_from'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:349:in `block in each_strongly_connected_component'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:347:in `each'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:347:in `call'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:347:in `each_strongly_connected_component'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:226:in `tsort_each'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:205:in `tsort_each'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/initializable.rb:60:in `run_initializers'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/application.rb:391:in `initialize!'
web_1  |        from /docker-test2/config/environment.rb:5:in `<main>'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
web_1  |        from /usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
web_1  |        from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/dependencies.rb:332:in `block in require'
web_1  |        from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/dependencies.rb:299:in `load_dependency'
web_1  |        from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/dependencies.rb:332:in `require'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `require_relative'
web_1  |        from config.ru:3:in `block in <main>'
web_1  |        from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:116:in `eval'
web_1  |        from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:116:in `new_from_string'
web_1  |        from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:105:in `load_file'
web_1  |        from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:66:in `parse_file'
web_1  |        from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:349:in `build_app_and_options_from_config'
web_1  |        from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:249:in `app'
web_1  |        from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:422:in `wrapped_app'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/commands/server/server_command.rb:77:in `log_to_stdout'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/commands/server/server_command.rb:37:in `start'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/commands/server/server_command.rb:144:in `block in perform'
web_1  |        from <internal:kernel>:90:in `tap'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/commands/server/server_command.rb:135:in `perform'
web_1  |        from /usr/local/bundle/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
web_1  |        from /usr/local/bundle/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
web_1  |        from /usr/local/bundle/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/command/base.rb:69:in `perform'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/command.rb:48:in `invoke'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/commands.rb:18:in `<main>'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
web_1  |        from /docker-test2/bin/rails:5:in `<top (required)>'
web_1  |        from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `load'
web_1  |        from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `call'
web_1  |        from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client/command.rb:7:in `call'
web_1  |        from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client.rb:30:in `run'
web_1  |        from /usr/local/bundle/gems/spring-2.1.1/bin/spring:49:in `<top (required)>'
web_1  |        from /usr/local/bundle/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `load'
web_1  |        from /usr/local/bundle/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `<top (required)>'
web_1  |        from /docker-test2/bin/spring:10:in `require'
web_1  |        from /docker-test2/bin/spring:10:in `block in <top (required)>'
web_1  |        from <internal:kernel>:90:in `tap'
web_1  |        from /docker-test2/bin/spring:7:in `<top (required)>'
web_1  |        from bin/rails:2:in `load'
web_1  |        from bin/rails:2:in `<main>'
web_1  | /usr/local/lib/ruby/3.0.0/psych.rb:581:in `initialize': No such file or directory @ rb_sysopen - /docker-test2/config/webpacker.yml (Errno::ENOENT)
web_1  |        from /usr/local/lib/ruby/3.0.0/psych.rb:581:in `open'
web_1  |        from /usr/local/lib/ruby/3.0.0/psych.rb:581:in `load_file'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/compile_cache/yaml.rb:124:in `load_file'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/configuration.rb:97:in `load'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/configuration.rb:92:in `data'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/configuration.rb:88:in `fetch'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/configuration.rb:43:in `public_path'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/configuration.rb:47:in `public_output_path'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/configuration.rb:51:in `public_manifest_path'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/manifest.rb:83:in `load'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/manifest.rb:18:in `refresh'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/commands.rb:47:in `bootstrap'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker.rb:35:in `bootstrap'
web_1  |        from /usr/local/bundle/gems/webpacker-5.4.2/lib/webpacker/railtie.rb:41:in `block in <class:Engine>'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/initializable.rb:32:in `instance_exec'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/initializable.rb:32:in `run'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/initializable.rb:61:in `block in run_initializers'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:228:in `block in tsort_each'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:431:in `each_strongly_connected_component_from'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:349:in `block in each_strongly_connected_component'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:347:in `each'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:347:in `call'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:347:in `each_strongly_connected_component'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:226:in `tsort_each'
web_1  |        from /usr/local/lib/ruby/3.0.0/tsort.rb:205:in `tsort_each'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/initializable.rb:60:in `run_initializers'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/application.rb:391:in `initialize!'
web_1  |        from /docker-test2/config/environment.rb:5:in `<main>'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
web_1  |        from /usr/local/bundle/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
web_1  |        from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/dependencies.rb:332:in `block in require'
web_1  |        from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/dependencies.rb:299:in `load_dependency'
web_1  |        from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/dependencies.rb:332:in `require'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `require_relative'
web_1  |        from config.ru:3:in `block in <main>'
web_1  |        from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:116:in `eval'
web_1  |        from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:116:in `new_from_string'
web_1  |        from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:105:in `load_file'
web_1  |        from /usr/local/bundle/gems/rack-2.2.3/lib/rack/builder.rb:66:in `parse_file'
web_1  |        from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:349:in `build_app_and_options_from_config'
web_1  |        from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:249:in `app'
web_1  |        from /usr/local/bundle/gems/rack-2.2.3/lib/rack/server.rb:422:in `wrapped_app'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/commands/server/server_command.rb:77:in `log_to_stdout'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/commands/server/server_command.rb:37:in `start'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/commands/server/server_command.rb:144:in `block in perform'
web_1  |        from <internal:kernel>:90:in `tap'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/commands/server/server_command.rb:135:in `perform'
web_1  |        from /usr/local/bundle/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
web_1  |        from /usr/local/bundle/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
web_1  |        from /usr/local/bundle/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/command/base.rb:69:in `perform'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/command.rb:48:in `invoke'
web_1  |        from /usr/local/bundle/gems/railties-6.1.4.1/lib/rails/commands.rb:18:in `<main>'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
web_1  |        from /usr/local/bundle/gems/bootsnap-1.8.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
web_1  |        from /docker-test2/bin/rails:5:in `<top (required)>'
web_1  |        from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `load'
web_1  |        from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in `call'
web_1  |        from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client/command.rb:7:in `call'
web_1  |        from /usr/local/bundle/gems/spring-2.1.1/lib/spring/client.rb:30:in `run'
web_1  |        from /usr/local/bundle/gems/spring-2.1.1/bin/spring:49:in `<top (required)>'
web_1  |        from /usr/local/bundle/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `load'
web_1  |        from /usr/local/bundle/gems/spring-2.1.1/lib/spring/binstub.rb:11:in `<top (required)>'
web_1  |        from /docker-test2/bin/spring:10:in `require'
web_1  |        from /docker-test2/bin/spring:10:in `block in <top (required)>'
web_1  |        from <internal:kernel>:90:in `tap'
web_1  |        from /docker-test2/bin/spring:7:in `<top (required)>'
web_1  |        from bin/rails:2:in `load'
web_1  |        from bin/rails:2:in `<main>'
docker-test2_web_1 exited with code 1

我发现有人说我必须先安装 webpacker,所以我尝试了类似的方法。 docker-compose run web bundle exec rails webpacker:install 错误说

Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/ Exiting!

我想我应该在图像中安装纱线,所以我也尝试了 docker run web shapt-get install yarn 但没有任何改变。

如果你能帮助我,我将不胜感激。

谢谢。

我在 Dockerfile 中添加了 RUN yarn install 并且它起作用了,但我仍然有问题。

  1. 将 Dockerfile 的第 2 行替换为以下内容
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client yarn
  1. docker-compose build

  2. docker-compose run --no-deps web rails webpacker:install