运行后无法访问docker Ruby on Rails映像



我是docker的新手,正在尝试学习一些教程。我正在关注这个:http://codingnudge.com/2017/03/17/tutorial-how-to-run-ruby-on-rails-on-docker-part-1/

并在运行docker镜像时在最后得到stack。

问题如下:

dockerfile:

FROM ruby:2.3.1
#Install essential linux packages
RUN apt-get update -qq
RUN apt-get install -y --no-install-recommends 
build-essential 
npm 
libpq-dev 
nodejs 
postgresql-client 
&& rm -rf /var/lib/apt/lists/*
#Define where the application will live inside the image
ENV RAILS_ROOT /var/www/app
#Create application home. App server will need the pids dir
RUN mkdir -p $RAILS_ROOT/tmp/pids
#Set our working directory inside the image
WORKDIR $RAILS_ROOT
#Install bundler
RUN gem install bundler
#Use the Gemfiles as Docker cache markers. Always bundle before copying app src.
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
#Finish establishing our Ruby enviornment
RUN bundle install --deployment
#Copy the Rails application into place
COPY . .
RUN RAILS_ENV=production bin/rails assets:precompile
RUN ls -la
CMD rails server --port 3000

我正在运行以下内容:

docker run -p 3001:3000 myapp

以及尝试通过访问应用程序时

localhost:3001 

它不起作用,并表示localhost没有发送任何数据。请帮我弄清楚我在这里做错了什么。

我正在为此运行Mac操作系统。

谢谢!

当您将--port参数提供给rails时,彪马将只侦听本地接口如果没有--port,它将监听所有接口。

因此,要强制彪马监听带有--port的所有接口,您必须明确告诉它这样做:

CMD rails server -b 0.0.0.0 --port 3000

这应该允许码头码头转发正常工作。

最新更新