【问题标题】:Unsupported config option for services.web: 'dockerfile'services.web 不支持的配置选项:'dockerfile'
【发布时间】:2019-08-19 15:24:22
【问题描述】:

我正在 docker 中使用 php 和 mysql 建立一个新环境。我正在使用 docker-compose 文件。在安装时我意识到我需要更多的 PHP 扩展。我已经在网上浏览了建议,建议编写一个 docker 文件并在 docker-compose.yml 中调用它。它总是显示以下错误 services.web 不支持的配置选项:'dockerfile'

请在下面找到 docker-compose.yml 和 Dockerfile

docker-compose.yml

version: '3'
services:
  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: asdf
      # MYSQL_DATABASE: test_db
      # MYSQL_USER: root
      # MYSQL_PASSWORD: asdf
    volumes:
      - /var/mysql/:/var/lib/mysql
    ports:
      - "3306:3306"
  web:
    # image: alankar1985/php7.2:apache2
    container_name: php_web
    dockerfile: Dockerfile
    # command: apt-get install -y php-gd
    depends_on:
      - db
    volumes:
      - /var/www/html/:/var/www/html/
    ports:
      - "80:80"
    stdin_open: true
    tty: true

Dockerfile

FROM alankar1985/php7.2:apache2

RUN apt install php-gd


services.web 不支持的配置选项:'dockerfile'

【问题讨论】:

  • 你检查过这个reference吗。以及交叉检查Docker版本
  • 很高兴听到 :) 不客气 :)

标签: docker-compose dockerfile


【解决方案1】:

解决此类问题的最佳方法是检查特定版本的 docker-compose 参考 - https://docs.docker.com/compose/compose-file/

没有测试,问题是因为你需要把 dockerfile 放在 build 下。

旧:

web:
  dockerfile: Dockerfile

新:

web:
  build:
    context: .
    dockerfile: Dockerfile

由于您使用的是标准 Dockerfile 文件名,因此您也可以使用:

build:
  context: .

来自参考页面:

DOCKERFILE 备用 Dockerfile。

Compose 使用备用文件进行构建。构建路径还必须 指定。

build:
  context: .
  dockerfile: Dockerfile-alternate

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-19
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    相关资源
    最近更新 更多