私はDockerを初めて使用し、デモ用Railsアプリケーションを作成しようとしています。ドッカーコンテナによるERR_CONNECTION_REFUSED
FROM ruby:2.2
# Install apt based dependencies required to run Rails as
# well as RubyGems. As the Ruby image itself is based on a
# Debian image, we use apt-get to install those.
RUN apt-get update && apt-get install -y \
build-essential \
nodejs
# Configure the main working directory. This is the base
# directory used in any further RUN, COPY, and ENTRYPOINT
# commands.
RUN mkdir -p /app
WORKDIR /app
# Copy the Gemfile as well as the Gemfile.lock and install
# the RubyGems. This is a separate step so the dependencies
# will be cached unless changes to one of those two files
# are made.
COPY Gemfile Gemfile.lock ./
RUN gem install bundler && bundle install --jobs 20 --retry 5
# Copy the main application.
COPY . ./
# Expose port 3000 to the Docker host, so we can access it
# from the outside.
EXPOSE 3000
# The main command to run when the container starts. Also
# tell the Rails dev server to bind to all interfaces by
# default.
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
が、私はそれ(エラーなし)を建て:
docker build -t demo .
し、それを実行します(また、エラーなし):
docker run -itP demo
=> Booting Puma
=> Rails 5.1.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.8.2 (ruby 2.2.7-p470), codename: Sassy Salamander
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:9292
Use Ctrl-C to stop
私はこのようになりますdockerfileを作りました別の端末でdocker ps
コマンドを実行してポートを確認すると、次のようになります。
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
55e8224f7c15 demo "bundle exec rails..." About an hour ago Up About an hour 0.0.0.0:32772->3000/tcp ecstatic_bohr
ただし、Chromeを使用して、またはcurlコマンドを使用してhttp://localhost:32772
またはhttp://192.168.99.100:32772
に接続しようとすると、「接続が拒否されました」というメッセージが表示されます。
bundle exec rails server
コマンドでローカルマシンのドッカーの外にアプリケーションを実行すると正常に動作します。私のWin7マシンでDocker Toolboxを使用していることに注意してください。
どうしたらいいですか?
ポート3000が公開されていますが、32772に到達しようとしていますか? –
私はコンテナ内に3000を公開しています。これは私が収集したものから自分のlocalhostの32772にマッピングされます(少なくとも "0.0.0.0:32772-> 3000/tcp"は "docker ps"で表示されます) – Donald
私は通常使っていますドッカーは私のドッカーファイルと一緒に、物事が自動化された一貫した方法で設定されていることを確認します。あなたのdockerファイルでは、 "ports"オプションを使い、ポートのようなことをします: "8000:8000"を左に8000はドッキングホスト、右に8000はドッカーコンテナーです。 – bkunzi01