Docker Rails App迁移问题

时间:2016-06-11 23:19:58

标签: ruby-on-rails docker elastic-beanstalk

我在迁移rails应用数据时遇到问题。我可以使用eb本地运行使应用程序正常运行,然后使用docker exec rake db迁移数据:migrate RAILS_ENV = production并运行迁移。然而,当我进入我的EB实例并运行相同的命令时,控制台挂起并且运行状况转为警告,说100%cpu在使用中,97%在i / o中等待。

**编辑:在日志中我看到PG :: ConnectionBad:无法翻译主机名" db"解决:名称或服务未知......再次在本地运行良好,因此不确定问题是什么。

** edit2(其他详细信息:)

在本地机器上采取的步骤:

1)eb本地运行

2)打开新终端,使用docker ps获取正在运行的docker id(下面的输出)

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

<docker id> <imagename> "rake run" 13 seconds ago Up 13 seconds 0.0.0.0:80->80/tcp elasticbeanstalk_web_1

<docker_id> postgres:latest "/docker-entrypoint.s" 14 seconds ago Up 13 seconds 5432/tcp, 0.0.0.0:5433->5431/tcp elasticbeanstalk_db_1

3)docker exec rake db:migrate RAILS_ENV = production 4)app成功迁移

当我进入aws容器时 1)docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

<container id> <image name> "rake run" 2 hours ago Up 2 hours 0.0.0.0:80->80/tcp ecs-awseb-app-env-apwxtv5mzf-8-web-aa9ca28485ed8ee69c01

<container id> postgres "/docker-entrypoint.s" 2 hours ago Up 2 hours 5432/tcp, 0.0.0.0:5433->5431/tcp ecs-awseb-app-env-apwxtv5mzf-8-db-8cb4a4b9daa3d8a50100

81ef33210e3a amazon/amazon-ecs-agent:latest "/agent" 19 hours ago Up 19 hours 127.0.0.1:51678->51678/tcp ecs-agent

2)docker exec rake db:migrate RAILS_ENV = production 3)收到错误:PG :: ConnectionBad:无法翻译主机名&#34; db&#34;解决:名称或服务未知耙中止!

dockerfile

FROM ruby:2.3.1
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
RUN gem update --system 2.6.1
RUN gem install bundler --version $BUNDLER_VERSION

RUN mkdir /app
WORKDIR /app

ADD Gemfile /app/Gemfile
ADD Gemfile.lock /app/Gemfile.lock

ENV BUNDLE_PATH /box
RUN bundle install

ADD . /app

ENTRYPOINT ["rake"]

Dockerrun.aws.json

        "AWSEBDockerrunVersion": 2,
        "containerDefinitions": [{
            "name": "db",
            "image": "postgres",
            "essential": true,
            "memory": 128,
            "portMappings": [{
                "hostPort": 5433,
                "containerPort": 5431
            }]
        }, {
            "name": "box",
            "image": "busybox",
            "essential": false,
            "memory": 128,
            "volumes": [{
                "host": {
                    "sourcePath": "/box"
                }
            }]
        }, {
            "name": "web",
            "image": "hughkolias/yuhu:test4",
            "essential": true,
            "memory": 128,
            "command": [
                "run"
            ],
            "volumes": [{
                "host": {
                    "sourcePath": ".:/yuhu"
                }
            }],
            "portMappings": [{
                "hostPort": 80,
                "containerPort": 80
            }],
            "links": [
                "db"
            ]
        }]
    }

非常感谢任何有关迁移的帮助!

提前致谢!

0 个答案:

没有答案