【发布时间】:2016-12-25 20:17:48
【问题描述】:
我一直在使用示例 ruby-on-rails 应用程序并在 linux 服务器 (ubuntu 14.04) 中部署 docker 映像。
这是我的 Dockerfile:
FROM ruby:2.1.5
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /rails_docker_demo
WORKDIR /rails_docker_demo
ADD Gemfile /rails_docker_demo/Gemfile
ADD Gemfile.lock /rails_docker_demo/Gemfile.lock
RUN bundle install
ADD . /rails_docker_demo
# CMD bundle exec rails s -p 3000 -b 0.0.0.0
# EXPOSE 3000
docker-compose.yml:
version: '2'
services:
db:
image: postgres
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
image: atulkhanduri/rails_docker_demos
volumes:
- .:/rails_docker_demo
ports:
- "3000:3000"
depends_on:
- db
部署.sh:
#!/bin/bash
docker build -t atulkhanduri/rails_docker_demo .
docker push atulkhanduri/rails_docker_demo
ssh username@ip-address << EOF
docker pull atulkhanduri/rails_docker_demo:latest
docker stop web || true
docker rm web || true
docker rmi atulkhanduri/rails_docker_demo:current || true
docker tag atulkhanduri/rails_docker_demo:latest atulkhanduri/rails_docker_demo:current
docker run -d --restart always --name web -p 3000:3000 atulkhanduri/rails_docker_demo:current
EOF
现在我的问题是我无法使用docker-compose 之类的命令来运行应用程序服务器,例如docker-compose up。
当我取消注释来自Dockerfile 的最后两行时,即
CMD bundle exec rails s -p 3000 -b 0.0.0.0
EXPOSE 3000
然后我可以在端口3000 上运行服务器,但出现错误could not translate host name "db" to address: Name or service not known。 (我的 database.yml 有“db”作为主机。)这是因为 postgres 图像未被使用,因为我没有使用 docker-compose 文件。
编辑:
docker network ls的输出:
NETWORK ID NAME DRIVER SCOPE
b466c9f566a4 bridge bridge local
7cce2e53ee5b host host local
bfa28a6fe173 none null local
P.S:我在互联网上搜索了很多,但还不能使用docker-compose 文件。
【问题讨论】:
标签: ruby-on-rails docker docker-compose dockerfile