如果我将Docker配置设置为目标端口3000,我的rails应用程序运行良好。但是我无法使其在端口80上运行。这是构建Web服务的Dockerfile:
FROM ruby:2.3.7
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
RUN apt-get install -y postgresql postgresql-contrib
RUN mkdir /app
WORKDIR /app
COPY Gemfile ./Gemfile
COPY Gemfile.lock ./Gemfile.lock
RUN gem install bundler
RUN bundle install
COPY . .
RUN cp config/database.docker-dev.yml config/database.yml
CMD [ "bundle", "exec", "rails", "s", "-p", "3000", "-b" "0.0.0.0" ]
这是docker-compose.yml:
version: '3'
services:
memcached:
image: memcached:1.5.2-alpine
restart: always
ports:
- "11211:11211"
postgres:
image: postgres:9.4-alpine
restart: always
volumes:
- ~/.engine-data/postgres:/var/lib/postgresql/data
ports:
- "5432:5432"
environment:
- POSTGRES_DB=app_development
- POSTGRES_USER=default
- POSTGRES_PASSWORD=secret
redis:
image: redis:3.2.0-alpine
restart: always
volumes:
- ~/.engine-data/redis:/data
ports:
- "6379:6379"
web:
build:
context: .
dockerfile: "Dockerfile-dev"
command: ./wait-for-it.sh redis:6379 -- ./wait-for-it.sh postgres:5432 -- bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/opt/apps/engine
depends_on:
- memcached
- redis
- postgres
ports:
- "80:3000"
env_file:
- .env
sidekiq:
build:
context: .
dockerfile: "Dockerfile-dev"
command: ./wait-for-it.sh redis:6379 -- ./wait-for-it.sh postgres:5432 -- bundle exec sidekiq
volumes:
- .:/opt/apps/engine
depends_on:
- web
- postgres
- redis
env_file:
- .env
elastic:
image: elasticsearch:1.5
volumes:
- ~/.engine-data/elasticsearch:/usr/share/elasticsearch/data
ports:
- "9200:9200"
- "9300:9300"
我尝试更改rails s
命令以使用端口80,然后在docker-compose上的Web服务中绑定80:80,但结果相同:服务器正在运行,但GET localhost:80无法到达它。 / p>