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.

  • cloudera manager can only inspect one host at a time
  • Dial tcp 127.0.0.1:55554: connectex: An attempt was made to access a socket in a way forbidden by its access permissions
  • docker running a data container from scratch
  • Getting User name + password to docker container
  • Docker - Limit mounted volume size
  • Problems with .net-core self contained publish
  • **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!

  • Configure Marathon-LB from docker-compose
  • Difference between docker restart & docker-compose restart
  • Docker connection refused hanging Django
  • Unable to push docker image to Openshift Origin Docker registry
  • Docker Swarm with Zookeeper - No elected primary cluster manager
  • custom docker image is not running postgres
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.