Docker撰写连接问题

时间:2017-03-04 12:32:50

标签: ruby-on-rails docker docker-compose

我尝试在docker中运行rails应用程序但是我遇到了docker-compose网络的问题,我认为......

我的Dockerfile如下所示:

FROM ruby:2.3-slim

RUN apt-get update \
 && apt-get install -qq -y --no-install-recommends \
    build-essential \
    nodejs \
    libpq-dev \
    git \
    tzdata \
    libxml2-dev \
    libxslt-dev \
    ssh \
 && rm -rf /var/lib/apt/lists/*

ENV APP_HOME /var/apps/books-store
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME

ENV GEM_HOME /var/apps/books-store/vendor/bundle
ENV PATH $GEM_HOME/bin:$PATH
ENV BUNDLE_PATH $GEM_HOME
ENV BUNDLE_BIN $BUNDLE_PATH/bin

EXPOSE 3000

我的docker-compose.yml看起来像这样:

version: '2'
services:
  database:
    image: postgres
    volumes:
      - ./data/pgdata:/pgdata
    ports:
      - '5555:5432'
    env_file:
      - '.env'
  web:
    links:
      - database
    build: .
    volumes:
      - .:/var/apps/books-store
    ports:
      - '3000:3000'
    command: [bundle, exec, puma]
    env_file:
      - '.env'
    stdin_open: true
    tty: true

当我尝试docker-compose up时,从日志中我看到rails服务器成功启动但是当我尝试从主机浏览器访问localhost:3000时它不起作用,我无法理解原因。我做错了什么?

docker ps:

407b59a2fa99   bookstore_web   "bundle exec puma"      About a minute ago  Up 41 seconds  0.0.0.0:3000->3000/tcp  bookstore_web
1837fc3e3f387  postgres        "docker-entrypoint..."  About a minute ago  Up 49 seconds  0.0.0.0:5555->5432/tcp  bookstore_database_1

docker-compose logs web:

Attaching to bookstore_web_1
web_1 | Puma starting in single mode...
web_1 | * Version 3.6.2 (ruby 2.3.3-p222), codename: Sleepy Sunday Serenity
web_1 | * Min threads: 0, max threads: 16
web_1 | * Environment: development
web_1 | * Listening on tcp://0.0.0.0:9292
web_1 | Use Ctrl-C to stop

0 个答案:

没有答案