在 运行 之后无法访问 Rails 图像上的 docker Ruby
Cannot access docker Ruby on Rails image after running
我是 docker 的新手,正在尝试学习一些教程。
我正在关注这个:
http://codingnudge.com/2017/03/17/tutorial-how-to-run-ruby-on-rails-on-docker-part-1/
并在 运行 图像 docker 的最后得到堆栈。
问题如下:
docker文件:
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
它不起作用,说本地主机没有发送任何数据。
请帮助我了解我在这里做错了什么。
为此我运行MacOS
谢谢!
当您向 rails
提供 --port
参数时,Puma 将只监听本地接口。 没有 --port
它将监听所有接口。
因此,要强制 Puma 监听所有接口 --port
,您必须明确告诉它这样做:
CMD rails server -b 0.0.0.0 --port 3000
这应该允许 docker 端口转发正常工作。
我是 docker 的新手,正在尝试学习一些教程。 我正在关注这个: http://codingnudge.com/2017/03/17/tutorial-how-to-run-ruby-on-rails-on-docker-part-1/
并在 运行 图像 docker 的最后得到堆栈。
问题如下:
docker文件:
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
它不起作用,说本地主机没有发送任何数据。 请帮助我了解我在这里做错了什么。
为此我运行MacOS
谢谢!
当您向 rails
提供 --port
参数时,Puma 将只监听本地接口。 没有 --port
它将监听所有接口。
因此,要强制 Puma 监听所有接口 --port
,您必须明确告诉它这样做:
CMD rails server -b 0.0.0.0 --port 3000
这应该允许 docker 端口转发正常工作。