首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >停靠容器上的连接被拒绝

停靠容器上的连接被拒绝
EN

Stack Overflow用户
提问于 2016-04-24 00:52:57
回答 4查看 150.4K关注 0票数 71

我是Docker新手,正在尝试制作一个演示Rails应用程序。我做了一个dockerfile,看起来像这样:

FROM ruby:2.2
MAINTAINER marko@codeship.com

# 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 8080 to the Docker host, so we can access it 
# from the outside.
EXPOSE 8080

# 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", "-p", "8080"]

然后我像这样构建它:

docker build -t demo . 

并调用一个命令来启动服务器,该服务器在端口8080上启动服务器:

Johns-MacBook-Pro:demo johnkealy$ docker run -it demo
=> Booting WEBrick
=> Rails 4.2.5 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-04-23 16:50:34] INFO  WEBrick 1.3.1
[2016-04-23 16:50:34] INFO  ruby 2.2.4 (2015-12-16) [x86_64-linux]
[2016-04-23 16:50:34] INFO  WEBrick::HTTPServer#start: pid=1 port=8080

然后,我尝试找到要导航到的正确IP:

Johns-MacBook-Pro:demo johnkealy$ docker-machine ip default
192.168.99.100

我导航到http://192.168.99.100:8080并得到错误这个站点不能到达192.168.99.100拒绝连接。

我能做错什么呢?

EN

回答 4

Stack Overflow用户

发布于 2019-09-22 00:59:54

我也有同样的问题。我在Windows Home上使用Docker Toolbox。我不得不使用http://192.168.99.100:8080/而不是localhost

您可以使用以下命令获取正确的IP地址:

docker-machine ip

上面的命令为我返回了192.168.99.100

票数 11
EN

Stack Overflow用户

发布于 2018-10-12 17:08:00

在Docker Quickstart终端中运行以下命令:

$ docker-machine ip 192.168.99.100 
票数 6
EN

Stack Overflow用户

发布于 2019-12-10 04:08:47

doesn文件中的命令EXPOSE允许您将容器的端口绑定到主机上的某个端口,但它不会做其他任何事情。运行容器时,要绑定端口,请指定-p选项。

因此,假设您公开了端口5000。在运行容器时构建镜像后,运行docker run -p 5000:5000 name。这将容器的端口5000绑定到您的笔记本电脑/计算机端口5000,并且该端口转发允许容器接收外部请求。

这个应该可以了。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36813690

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档