Docker Rails App migration issue

I’m having an issue migrating my rails app data. I can get the app running fine using eb local run, then migrating the data using docker exec rake db:migrate RAILS_ENV=production and it runs the migrations. However when I ssh into my EB instance and run the same command, the console hangs and the health shifts to warning, saying 100% cpu in use and 97% in i/o wait.

**edit: in the logs I see PG::ConnectionBad: could not translate host name “db” to address: Name or service not known… again it runs fine locally so not sure what the issue is.

  • Easy moving of environments: deploybot, docker or manual grunt/gulp setup?
  • is it possible to ssh into docker container which is not running ( or exited )?
  • Exec into docker cloud?
  • Deploying Java app to Docker image
  • couldn't run docker when mount volume
  • Importing a MySQL database with a Python script fails when the same command works on the command line, what gives?
  • **edit2 (additional details:)

    Steps taken on local machine:

    1) eb local run

    2) open new terminal, obtain running docker id using docker ps (output below)

    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 migrates successfully

    When I ssh into the aws container
    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) receive error: PG::ConnectionBad: could not translate host name “db” to address: Name or service not known rake aborted!

    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"
                ]
            }]
        }
    

    Any help on migrating would be greatly appreciated!

    Thanks in advance!

  • When, where and how does Visual Studio 2017 set the DOCKER_BUILD_SOURCE environment variable
  • Deploying multi-docker local setup to AWS using Elastic Beanstalk
  • Running new meteorhacks/meteord application, don't have meteor app
  • Issue to node-sass and Docker
  • Managing and Utilizing Multiple Docker Containers (Microservices) in a Single Server
  • Why is my docker image size much bigger than my application?
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.