ERR_CONNECTION_REFUSED由码头集装箱
问题描述:
我是新来的Docker,并试图做一个演示Rails应用程序。我做了一个dockerfile,看起来像这样: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
当我在一个单独的终端运行一个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
我该做什么错?
答
上述招数worked--
我不得不使用http://<VM IP ADDRESS>:32772
组合(本地主机:32772没有工作),我不得不解决我暴露的端口匹配的9292
我仍然不明白为什么TCP侦听端口默认为9292而不是3000,但我会分开研究。
谢谢你的帮助!
答
我花了几个小时在这个以及thread真的很有帮助。我现在正在通过虚拟机的IP地址访问这些服务。
你可以让你的虚拟机的运行地址:
docker-machine ls
然后尝试使用主机映射端口37772,这样的事情来访问服务:
http://<VM IP ADDRESS>:32772
希望这有助于。
您公开端口3000,但您试图达到32772? –
我在容器中暴露3000,然后从我收集的内容(至少每个“0.0.0.0:32772->3000/tcp”通过“docker ps”显示)映射到我的本地主机上的32772) – Donald
我通常使用码头工人与我的码头文件一起撰写,以确保事物以自动和一致的方式进行设置。在您的dockerfile中,您将使用“ports”选项并执行类似端口的操作:“8000:8000”left 8000是docker host,右边是8000 docker container。 – bkunzi01