Docker Composer 오류 해결하기 – services.server.build contains unsupported option: ‘image’

아래와 같이 docker-composer 실행하면 바로 에러가 뜨는 경우가 있는데요.

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.server.ports contains an invalid type, it should be an array
services.server.build contains unsupported option: 'image'

이 에러는 보통 탭이나 빈칸으로 범위를 나타내는 yml 문법에 익숙하지 않아서 나타나는 문제인 경우가 많습니다.

예를 들어 docker-composer 설정파일 내용이 다음과 같은 경우 입니다.

# 잘못된 예
version: '2'

services:
  admin:
    build:
      ###################
      image: docker.hub/image
      ###################
      context: ./
      dockerfile: ./Dockerfile
    ports:
      - "3001:3001"

build 하위 항목으로 image 가 들어가 있습니다. build 에는 없는 옵션항목이기 때문에 맨 위에 보여드린 에러를 출력하게 됩니다. 바르게 고치면 다음과 같이 바꾸면 되겠습니다.

# 바른 예
version: '2'

services:
  admin:
    ###################
    image: docker.hub/image
    ###################
    build:
      context: ./
      dockerfile: ./Dockerfile
    ports:
      - "3001:3001"

YML 형식은 간편하지만 들여쓰기로 구분하는 부분은 눈에 바로 들어오지 않는 경우가 있으니 주의하시기 바랍니다. ^^