简体   繁体   中英

build contains unsupported option: 'ports'

Trying to use docker-compose for the first time, but not having much luck. I have the following setup: docker-compose version 1.8.0, build f3628c7

  • /home/GabeThermComposer contains the docker-compose.yml
  • /home/GabeThermComposer/GabeThermApache contains Dockerfile
  • /home/GabeThermComposer/GabeThermPHPMyAdmin contains Dockerfile
  • /home/GabeThermComposer/GabeThermDB contains Dockerfile and nest-init.sql

When I create docker images using the Dockerfile in each subdir, it all works without issues. I was hoping with the docker-compose.yml to do all the seperate building of images at once.

The docker-compose.yml looks like this:

version: '2'
services:
  GabeThermDB:
    build:
      context: ./GabeThermDB
      dockerfile: Dockerfile

  GabeThermApache:
    build:
      context: ./GabeThermApache
      dockerfile: Dockerfile
      ports:
       - "80:80"

  GabeThermPHPMyAdmin:
    build:
      context: ./GabeThermPHPMyAdmin
      dockerfile: Dockerfile
      ports:
       - "8080:80"

When trying to run "docker-compose up", I get the following error:

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.GabeThermPHPMyAdmin.build contains unsupported option: 'ports'
services.GabeThermApache.build contains unsupported option: 'ports'

I have no clue on what is wrong with this. I think I did exactly as other examples have shown. Btw, I do know that the "context:" and "dockerfile:" is overdone, but since I'm new, I wanted to be sure to what files I'm pointing in case I forget it automatically dives into the subdir and runs the Dockerfile.

Any help is appreciated.

You have to move the ports out of the build block.

version: '2'
services:
  GabeThermDB:
    build:
      context: ./GabeThermDB
      dockerfile: Dockerfile

  GabeThermApache:
    build:
      context: ./GabeThermApache
      dockerfile: Dockerfile
    ports:
      - "80:80"

  GabeThermPHPMyAdmin:
    build:
      context: ./GabeThermPHPMyAdmin
      dockerfile: Dockerfile
    ports:
      - "8080:80"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM