[英]Error running rails app on docker container of official Ruby image
[英]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映像時在最后獲得堆棧。
問題如下:
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 OS。
謝謝!
當向rails
提供--port
參數時,Puma將僅偵聽本地接口。 如果沒有 --port
,它將監聽所有接口。
因此,要強制Puma 使用 --port
監聽所有接口,您必須明確告訴它這樣做:
CMD rails server -b 0.0.0.0 --port 3000
這應該允許docker端口轉發正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.