Docker-Compose Up Works但Eb Local Run没有

时间:2016-09-25 09:06:52

标签: docker elastic-beanstalk docker-compose dockerfile amazon-elastic-beanstalk

附件是我的docker-compose文件。它是一个非常简单的项目,带有数据库和phpmyadmin来访问它。

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

如果我运行它,它工作正常。我创建了针对Elastic Beanstalk的Amazon Docker Run的等价物,它启动但由于某种原因,它无法在.data文件夹中找到保存我的持久数据库数据的卷。

我尝试过将.data更改为数据没有运气。

尝试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: )

我不知道如何解决此错误或其原因。有什么想法吗?

哎呀忘了添加我的亚马逊文件:)。

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

1 个答案:

答案 0 :(得分:2)

不要使用相对路径。

在部署之前使用 eb本地运行进行测试,它将帮助您解决部署问题。您的 Dockerrun.aws.json 文件将转换为 docker-compose.yml 文件,并使用docker的本地副本开始。

您可以在项目目录中的路径 .elasticbeanstalk / docker-compose.yml 中找到生成的docker-compose.yml。您会注意到docker-compose配置文件中缺少卷。

要解决此问题,请将您的卷更改为:

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

并在您的应用中创建目录,然后“eb local run”将正确转换它们。

eb deploy现在应该可以正常工作。