前提・実現したいこと
Dockerにlocalhost:3000で接続したいです。どなたかアドバイスを頂けないでしょうか?
発生している問題・エラーメッセージ
※chrome このサイトにアクセスできませんlocalhost で接続が拒否されました。 次をお試しください 接続を確認する プロキシとファイアウォールを確認する ERR_CONNECTION_REFUSED
https://qiita.com/chisaki0606/items/a4b42af5c4735c94057a
↑こちらの記事を参考にDockerでRailsの環境構築を行いました。その後、Dockerの再起動をしたいと思い、docker-compose down
を実行した後、docker-compose up
を行いました。
再びDockerを起動すると、http://localhost:3000
では、”localhost で接続が拒否されました。”と出るようになってしまいました。
試したこと
https://web.plus-idea.net/on/docker-web-server-access-denied/
↑こちらを参考に
docker exec -it <起動したコンテナ名> bash >>Error response from daemon: Container 7049dd94e1802520be68b5bf90d136fbc5d74bf4557f707a04bf3a2383e3aed2 is not running
curl http://localhost:8080/ >><!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
ポートフォワードを確認する
docker run -p 8080:3000 –name <起動するコンテナ名> >>docker: invalid reference format. See 'docker run --help'.
Docker logs 7049dd94e180 >>/usr/local/bundle/gems/webpacker-4.3.0/lib/webpacker/configuration.rb:95:in `rescue in load': Webpacker configuration file not found /myapp/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /myapp/config/webpacker.yml (RuntimeError) from /usr/local/bundle/gems/webpacker-4.3.0/lib/webpacker/configuration.rb:91:in `load' from /usr/local/bundle/gems/webpacker-4.3.0/lib/webpacker/configuration.rb:88:in `data' . . . from /usr/local/bundle/gems/bootsnap-1.7.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' from bin/rails:4:in `<main>' => Booting Puma => Rails 5.2.4.4 application starting in development => Run `rails server -h` for more startup options Exiting
Error: No such file or directory @ rb_sysopen - /myapp/config/webpacker.yml (RuntimeError)
Docker logsのエラーからwebpacker.yml
が足りないのだと思いrails webpacker:install
し、もう一度を行いましたが結果は変わりませんでした。
Docker logs 7049dd94e180 >>上記と同じエラー
補足情報(FW/ツールのバージョンなど)
Mac OSX
ruby 2.6.3
Rails 6.0.3.4
webpacker 4.3.0
Docker version 20.10.2
Dockerfile
1FROM ruby:2.7 2RUN apt-get update -qq && \ 3 apt-get install -y apt-utils \ 4 build-essential \ 5 libpq-dev \ 6 nodejs \ 7 default-mysql-client \ 8 yarn 9RUN mkdir /myapp 10WORKDIR /myapp 11COPY Gemfile /myapp/Gemfile 12COPY Gemfile.lock /myapp/Gemfile.lock 13RUN bundle install 14COPY . /myapp 15USER postgres 16 17 18# Add a script to be executed every time the container starts. 19COPY entrypoint.sh /usr/bin/ 20RUN chmod +x /usr/bin/entrypoint.sh 21ENTRYPOINT ["entrypoint.sh"] 22EXPOSE 3000 23 24# Start the main process. 25CMD ["rails", "server", "-b", "0.0.0.0"] 26 27# Railsに必要なパッケージをインストール 28RUN apt-get update -qq && apt-get install -y nodejs 29RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \ 30 && apt-get install -y nodejs 31 32EXPOSE 8080 33
docker-compose.yml
version: '3' services: db: image: postgres volumes: - ./tmp/db:/var/lib/postgresql/data environment: POSTGRES_PASSWORD: 'postgres' 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 postgres: image: postgres:13 user: postgres
Gemfile
1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4 5gem 'rails', '~> 6.0.3.4' 6gem 'puma', '~> 3.11' 7gem 'sassc-rails', '2.1.2' 8gem 'uglifier', '>= 1.3.0' 9gem 'coffee-rails', '~> 4.2' 10gem 'turbolinks', '~> 5' 11gem 'jbuilder', '~> 2.5' 12gem 'bootsnap', '>= 1.1.0', require: false 13gem 'bootstrap', '~> 4.5.0' 14gem 'jquery-rails' 15gem 'webpacker', '~> 4.0' 16 17 18group :development, :test do 19 gem 'rspec-rails' 20 gem 'sqlite3' 21 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 22end 23 24group :development do 25 gem 'web-console', '>= 3.3.0' 26 gem 'listen', '>= 3.0.5', '< 3.2' 27 gem 'spring' 28 gem 'spring-watcher-listen', '~> 2.0.0' 29end 30 31group :test do 32 gem 'capybara', '>= 2.15' 33 gem 'selenium-webdriver' 34 gem 'chromedriver-helper' 35end 36 37group :production do 38 gem 'pg' 39end 40 41gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 42
webpacker.yml
webpacker.yml
1# Note: You must restart bin/webpack-dev-server for changes to take effect 2 3default: &default 4 source_path: app/javascript 5 source_entry_path: packs 6 public_root_path: public 7 public_output_path: packs 8 cache_path: tmp/cache/webpacker 9 check_yarn_integrity: false 10 webpack_compile_output: true 11 12 # Additional paths webpack should lookup modules 13 # ['app/assets', 'engine/foo/app/assets'] 14 resolved_paths: [] 15 16 # Reload manifest.json on all requests so we reload latest compiled packs 17 cache_manifest: false 18 19 # Extract and emit a css file 20 extract_css: false 21 22 static_assets_extensions: 23 - .jpg 24 - .jpeg 25 - .png 26 - .gif 27 - .tiff 28 - .ico 29 - .svg 30 - .eot 31 - .otf 32 - .ttf 33 - .woff 34 - .woff2 35 36 extensions: 37 - .mjs 38 - .js 39 - .sass 40 - .scss 41 - .css 42 - .module.sass 43 - .module.scss 44 - .module.css 45 - .png 46 - .svg 47 - .gif 48 - .jpeg 49 - .jpg 50 51development: 52 <<: *default 53 compile: true 54 55 # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules 56 check_yarn_integrity: true 57 58 # Reference: https://webpack.js.org/configuration/dev-server/ 59 dev_server: 60 https: false 61 host: localhost 62 port: 3035 63 public: localhost:3035 64 hmr: false 65 # Inline should be set to true if using HMR 66 inline: true 67 overlay: true 68 compress: true 69 disable_host_check: true 70 use_local_ip: false 71 quiet: false 72 pretty: false 73 headers: 74 'Access-Control-Allow-Origin': '*' 75 watch_options: 76 ignored: '**/node_modules/**' 77 78 79test: 80 <<: *default 81 compile: true 82 83 # Compile test packs to a separate directory 84 public_output_path: packs-test 85 86production: 87 <<: *default 88 89 # Production depends on precompilation of packs prior to booting for performance. 90 compile: false 91 92 # Extract and emit a css file 93 extract_css: true 94 95 # Cache manifest.json for performance 96 cache_manifest: true 97
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。