无法在Docker映像中使用Composer安装依赖项

时间:2018-06-24 17:20:54

标签: php docker composer-php

我正在尝试使用docker安装Attendise。

当我输入此命令时:

$ docker run --rm -v $(pwd):/app composer/composer install

然后我收到此错误消息。

Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - symfony/class-loader v3.4.8 requires php ^5.5.9|>=7.0.8 -> your PHP version (7.0.7) does not satisfy that requirement.
    - symfony/class-loader v3.4.8 requires php ^5.5.9|>=7.0.8 -> your PHP version (7.0.7) does not satisfy that requirement.
    - Installation request for symfony/class-loader v3.4.8 -> satisfiable by symfony/class-loader[v3.4.8].

这是我的composer.json

{
    "name":"attendize/attendize",
    "description":"A free and open-source event management and ticket selling application.",
    "keywords":[
        "event management",
        "ticket selling",
        "tickets",
        "events"
    ],
    "license":"Attribution Assurance License",
    "type":"project",
    "homepage":"https://www.attendize.com",
    "require":{
        "laravel/framework":"5.2.*",
        "laravelcollective/html":"~5.0",
        "milon/barcode":"dev-master",
        "iron-io/iron_mq":"2.*",
        "intervention/image":"dev-master",
        "nitmedia/wkhtml2pdf":"dev-master",
        "maatwebsite/excel":"~2.0.0",
        "dompdf/dompdf":"dev-master",
        "laravel/socialite":"~2.0",
        "filp/whoops":"~1.0",
        "vinelab/http":"dev-master",
        "mews/purifier":"~2.0",
        "league/flysystem-aws-s3-v3":"~1.0",
        "maxhoffmann/parsedown-laravel":"dev-master",
        "omnipay/common":"~2.3",
        "omnipay/stripe":"*",
        "omnipay/paypal":"*",
        "omnipay/bitpay":"dev-master",
        "omnipay/coinbase":"dev-master",
        "laracasts/utilities":"^2.1",
        "predis/predis":"~1.0",
        "guzzlehttp/guzzle":"^6.2",
        "omnipay/migs":"^2.1",
        "mcamara/laravel-localization":"^1.2",
        "potsky/laravel-localization-helpers":"2.3.*"
    },
    "require-dev":{
        "phpunit/phpunit":"~4.0",
        "phpspec/phpspec":"~2.1",
        "fzaninotto/faker":"^1.5",
        "symfony/dom-crawler":"~3.0",
        "symfony/css-selector":"~3.0",
        "doctrine/dbal":"~2.3",
        "barryvdh/laravel-ide-helper":"^2.1"
    },
    "autoload":{
        "classmap":[
            "database",
            "app/Http/Controllers",
            "app/Models",
            "app/Attendize"
        ],
        "psr-4":{
            "App\\":"app/",
            "Attendize\\":"app/Models"
        }
    },
    "autoload-dev":{
        "classmap":[
            "tests/TestCase.php"
        ]
    },
    "scripts":{
        "post-install-cmd":[
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd":[
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd":[
            "php -r \"copy('.env.example', '.env');\"",
            "php artisan key:generate"
        ]
    },
    "config":{
        "preferred-install":"dist"
    },
    "extra":{
        "laravel":{
            "dont-discover":[
                "potsky/laravel-localization-helpers"
            ]
        }
    }
}

我不知道出什么问题了,因为我是新手。 请帮我 谢谢。

#docker-composer.yml

version: '2'

services:
  web:
    build:
      context: .
      dockerfile: Dockerfile-nginx
    ports:
    - "8080:80"
    networks:
      - attendizenet
    volumes:
      - .:/usr/share/nginx/html/attendize
    depends_on:
      - php
  php:
    build:
      context: .
      dockerfile: Dockerfile-php
    depends_on:
      - db
      - maildev
      - redis
    volumes:
      - .:/usr/share/nginx/html/attendize
    networks: 
      - attendizenet
  php-worker:
    build:
      context: .
      dockerfile: Dockerfile-php
    depends_on:
      - db
      - maildev
      - redis
    volumes:
      - .:/usr/share/nginx/html/attendize
    command: php artisan queue:work --daemon
    networks:
      - attendizenet
  db:
    image: postgres
    environment:
      - POSTGRES_USER=attendize
      - POSTGRES_PASSWORD=attendize
      - POSTGRES_DB=attendize
    ports:
      - "5433:5432"
    volumes:
      - ./docker/pgdata:/var/lib/postgresql/data
    networks:
    - attendizenet
  maildev:
    image: djfarrelly/maildev
    ports:
      - "1080:80"
    networks:
      - attendizenet
  redis:
    image: redis
    networks:
      - attendizenet

networks:
  attendizenet:
    driver: bridge

2 个答案:

答案 0 :(得分:2)

问题是您的Docker映像7.0.7提供的PHP版本低于composer.json中定义的一个或多个依赖项所要求的PHP版本。

要解决此问题,您有多种选择:

如果您共享Dockerfile,将会很有帮助。

答案 1 :(得分:0)

删除composer/composer图像和容器并修剪它可能就足够了。然后再次构建它。

似乎有更多可用的PHP 7.0.x最新版本。并且仅此一项就可以满足平台依赖项的不匹配。

..或者您可以尝试像这样运行install

$ composer install --ignore-platform-reqs
  • 这将忽略不匹配并继续进行安装。对于development,这可能不够,也可能不足。我不建议您忽略production的要求(除非您真的知道自己在做什么)。