我是新来的Docker并试图制作一个演示Rails应用程序。我做了一个dockerfile,看起来像这样:码头集装箱拒绝连接
FROM ruby:2.2
MAINTAINER [email protected]
# 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拒绝连接。
我会做什么错?
尝试使用发布选项运行容器。 docker run -it demo --publish 8080:8080 –
thanks,@jozef,但是我得到了“docker:来自守护进程的错误响应:容器命令'--publish'找不到或不存在..” – jdkealy