码头集装箱上的连接被拒绝

编程入门 行业动态 更新时间:2024-10-24 03:26:51
本文介绍了码头集装箱上的连接被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I'm new to Docker and trying to make a demo Rails app. I made a dockerfile that looks like this:

FROM ruby:2.2 MAINTAINER marko@codeship # 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上启动了服务器:

And call a command to start the server which does start the server on port 8080:

Johns-MacBook-Pro:demo johnkealy$ docker run -it demo => Booting WEBrick => Rails 4.2.5 application starting in development on 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进行导航:

I then try to find the correct IP to navigate to:

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

我导航到 192.168.99.100:8080 并收到错误此网站可以不能达到192.168.99.100拒绝连接。

I navigate to 192.168.99.100:8080 and get the error This site can’t be reached 192.168.99.100 refused to connect.

我该怎么办?

推荐答案

您需要使用以下选项发布公开的端口:

You need to publish the exposed ports by using the following options:

-P(大写)或--publish-all ,它们将告诉Docker使用来自主机的随机端口并将它们映射到暴露的容器的端口。

-P (upper case) or --publish-all that will tell Docker to use random ports from your host and map them to the exposed container's ports.

-p(小写)或--publish = [] ,它们将告诉Docker使用您手动设置的端口并将它们映射到暴露的容器的端口。

-p (lower case) or --publish=[] that will tell Docker to use ports you manually set and map them to the exposed container's ports.

首选第二个选项,因为您已经知道要映射的端口。如果使用第一个选项,则需要调用 docker inspect demo 并在端口部分中检查主机使用的随机端口。

The second option is preferred because you already know which ports are mapped. If you use the first option then you will need to call docker inspect demo and check which random ports are being used from your host at the Ports section.

只需运行以下命令:

docker run -it -p 8080:8080 demo

之后,您的网址即可使用。

After that your url will work.

更多推荐

码头集装箱上的连接被拒绝

本文发布于:2023-06-10 22:54:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/620831.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:集装箱   码头   被拒

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!