Ruby on rails Docker,can';t reach“;rails服务器";使用docker标志从localhost:3000进行开发-p 3000:3000

Ruby on rails Docker,can';t reach“;rails服务器";使用docker标志从localhost:3000进行开发-p 3000:3000,ruby-on-rails,docker,boot2docker,Ruby On Rails,Docker,Boot2docker,我尝试使用docker和rails,在一个容器中构建整个堆栈。我的最终目标是拥有一个nginx/memcached/unicorn/rails/postgres堆栈,并使用runit作为流程管理器。到目前为止,我已经安装了我的应用程序ruby和postgres。现在,在我转到nginx/memcached/unicorn之前,我正在尝试测试一切是否正常工作。 这是我的dockerfile: FROM ubuntu:trusty ADD . /app # Update repos RUN ap

我尝试使用docker和rails,在一个容器中构建整个堆栈。我的最终目标是拥有一个nginx/memcached/unicorn/rails/postgres堆栈,并使用runit作为流程管理器。到目前为止,我已经安装了我的应用程序ruby和postgres。现在,在我转到nginx/memcached/unicorn之前,我正在尝试测试一切是否正常工作。
这是我的dockerfile:

FROM ubuntu:trusty

ADD . /app

# Update repos
RUN apt-get update

# General 
RUN apt-get install -y git curl software-properties-common python-software-properties ssh

# Install ruby (taken from https://gist.github.com/konklone/6662393)
RUN \curl -Lk https://get.rvm.io | bash -s stable
RUN /bin/bash -l -c "rvm requirements"
RUN /bin/bash -l -c "rvm install 2.1.1"
ENV PATH /usr/local/rvm/gems/ruby-2.1.1/bin:/usr/local/rvm/rubies/ruby-2.1.1/bin:$PATH
RUN gem install bundler --no-ri --no-rdoc

# Install nodejs (rails js runtime)
RUN apt-get install -y nodejs

# Install postgresql (adapted from https://wiki.postgresql.org/wiki/Apt)
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -sc)-pgdg main"
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN apt-get update
RUN apt-get install -y postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3

# Setup postgresql
RUN mkdir /pgsql && chown postgres /pgsql
USER postgres
ENV PATH $PATH:/usr/lib/postgresql/9.3/bin/
RUN initdb -E UTF8 -D /pgsql/data
USER root

# Needed for pg gem (from http://stackoverflow.com/a/20754173)
RUN apt-get install -y libpq-dev
然后使用以下命令创建一个容器

docker run -it -p 3000:3000 *dockerfile_image* /bin/bash -l
在该容器中,我将postgresql设置为后台作业,并运行rails

$ sudo -u postgres /usr/lib/postgresql/9.3/bin/postgres -D /pgsql/data
^z
$ bg
$ sudo -u postgres /usr/bin/psql -c "create role *appname* login createdb"
$ cd /app
$ bundle && rake db:create db:migrate
$ rails s
=> Booting WEBrick
=> Rails 4.1.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
....
但正如标题所述,我无法从localhost:3000连接。 我也试过了

  • 正在尝试从0.0.0.0:3000连接
  • 离开-p 3000:3000并尝试从容器\u ip:3000连接
  • 在dockerfile中公开3000,使用docker ps查找映射端口并尝试localhost:mapped_port

我也不知道这是否重要,但我在OSX上使用boot2docker。

这实际上是由boot2docker造成的。有关更多信息,请参阅本页:

TLDR

Portforwarding目前只适用于boot2docker上的黑客攻击。您需要运行以下命令(并保持其运行):


其中80是容器上的暴露端口,8080是您希望从主机上访问容器的端口。

另请参见docker machine中的此操作不再有效。有人知道docker machine的正确调用是什么样子的吗?提示:-我不使用docker机器ssh。
boot2docker ssh -L 8080:localhost:80