Search code examples
docker-composedockerfile

Unsupported config option for services.web: 'dockerfile'


I am setting up a new environment with php and mysql in docker. i am using docker-compose file. while installing i realize that i need few more PHP extentensions. I have gone through suggestion online where it is suggested to write a docker file and call it in docker-compose.yml. it is alwasy showing below error Unsupported config option for services.web: 'dockerfile'

please find docker-compose.yml and Dockerfile below

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


Unsupported config option for services.web: 'dockerfile'


Solution

  • The best way to troubleshoot these type of issues is checking the docker-compose reference for the specific version - https://docs.docker.com/compose/compose-file/.

    Without testing, the issue is because you need to put dockerfile under build.

    Old:

    web:
      dockerfile: Dockerfile
    

    New:

    web:
      build:
        context: .
        dockerfile: Dockerfile
    

    Since you are using the standard Dockerfile filename, you could also use:

    build:
      context: .
    

    From reference page:

    DOCKERFILE Alternate Dockerfile.

    Compose uses an alternate file to build with. A build path must also be specified.

    build:
      context: .
      dockerfile: Dockerfile-alternate