LoginSignup
9
10

More than 5 years have passed since last update.

docker-composeで ERROR: In file './docker-compose.yml', service 'ports' must be a mapping not an array. が出た時の対処

Posted at

おもむろに docker-compose up したらエラーが出て困ったので原因を書いておく

エラー内容

docker-compose up
ERROR: In file './docker-compose.yml', service 'ports' must be a mapping not an array.

原因

docker-compose.ymlのインデントがおかしかった

こんな感じだったんだけども、 privileged 以下のインデントが1個足りてない

間違ったdocker-compose.yml
version: "3.3"
services:
  test-server:
  privileged: true
  build:
    context: .
  env_file: .env
  ports:
    - "8080:80"
  volumes:
    - ./src:/app:cached
  working_dir: /app/
  command: pwd

正しくはこう

正しいdocker-compose.yml
version: "3.3"
services:
  test-server:
    privileged: true
    build:
      context: .
    env_file: .env
    ports:
      - "8080:80"
    volumes:
      - ./src:/app:cached
    working_dir: /app/
    command: pwd
9
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
10