Joseph Astrahan
Joseph Astrahan

Reputation: 9072

Docker-Compose Up Works but Eb Local Run does not

Attached is my docker-compose file. Its a very simple project with a database and phpmyadmin to access it.

web:
    build: ./docker_web/
    links:
        - db
    ports: 
        - "80:80"
    volumes: 
        - "./docker_web/www/:/var/www/site"
db:
    image: mysql:latest
    restart: always
    volumes:
      - "./.data/db:/var/lib/mysql"
    environment:
      MYSQL_ROOT_PASSWORD: ^^^^
      MYSQL_DATABASE: electionbattle
      MYSQL_USER: admin
      MYSQL_PASSWORD: ^^^^
phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin
    environment:
     - PMA_ARBITRARY=1
    restart: always
    ports:
     - 8081:80
    volumes:
     - /sessions
    links:
        - db

If I run this it works fine. I created the equivlent for Amazon Docker Run for Elastic Beanstalk and it starts up but for some reason it can't find the volume that is holding my persisted database data in the .data folder.

I've tried changing .data to just data no luck.

Also I get a weird error when trying to do eb deploy

2016-09-24 19:56:10 UTC-0700    ERROR   ECS task stopped due to: Essential container in task exited. (db: CannotCreateContainerError: API error (500): create ./.data/db/: "./.data/db/" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed web: phpmyadmin: )

I have no idea how to fix this error or why its happening. Any ideas?

Oops forgot to add my amazon file :).

{
  "AWSEBDockerrunVersion": 2,
  "volumes": [
    {
      "name": "web",
      "host": {
        "sourcePath": "./docker_web/www/"
      }
    },
    {
      "name": "db",
      "host": {
        "sourcePath": "./data/db/"
      }
    }
  ],
  "containerDefinitions": [
    {
      "name": "web",
      "image": "197984628663.dkr.ecr.us-west-1.amazonaws.com/electionbattleonline",
      "memory": 200,
      "essential": true,
      "mountPoints": [
        {
          "sourceVolume": "web",
          "containerPath": "/var/www/site",
          "readOnly": false
        }
      ],
      "links": [
        "db"
      ],
      "portMappings": [
        {
          "hostPort": 80,
          "containerPort": 80
        }
      ]
    },
    {
      "name": "db",
      "image": "mysql:latest",
      "environment": [
        {
          "name": "MYSQL_ROOT_PASSWORD",
          "value": "^^^^"
        },
        {
          "name": "MYSQL_DATABASE",
          "value": "electionbattleonline"
        },
        {
          "name": "MYSQL_USER",
          "value": "admin"
        },
        {
          "name": "MYSQL_PASSWORD",
          "value": "^^^^"
        }
      ],
      "portMappings": [
      {
        "hostPort": 3306,
        "containerPort": 3306
      }
      ],
      "mountPoints": [
        {
          "sourceVolume": "db",
          "containerPath": "/var/lib/mysql",
          "readOnly": false
        }
      ],
      "essential": true,
      "memory": 200
    },
    {
      "name": "phpmyadmin",
      "image": "phpmyadmin/phpmyadmin",
      "environment": [
        {
          "name": "PMA_ARBITRARY",
          "value": "1"
        }
      ],
      "essential": true,
      "memory": 128,
      "links": [
        "db"
      ],
      "portMappings": [
        {
          "hostPort": 8081,
          "containerPort": 80
        }
      ]
    }
  ]
}

Upvotes: 1

Views: 2328

Answers (1)

BitByteDog
BitByteDog

Reputation: 3484

Don't use relative paths.

Use eb local run to test before deploying, it will help you solve deployment issues. Your Dockerrun.aws.json file will be converted into a docker-compose.yml file and started using a local copy of docker.

You can find the generated docker-compose.yml in your project directory at the path .elasticbeanstalk/docker-compose.yml. You will notice that your volumes are missing from the docker-compose config file.

To fix this change your volumes to:

"volumes": [
  {
    "name": "web",
    "host": {
      "sourcePath": "/var/app/current/docker_web/www/"
    }
  },
  {
    "name": "db",
    "host": {
      "sourcePath": "/var/app/current/data/db/"
    }
  }
],

and create the directories in your app, then "eb local run" will correctly convert them.

eb deploy should now work correctly.

Upvotes: 2

Related Questions