docker compose up -d エラー mapping key "~~" already defined
Q&A
Closed
実現したいこと
docker compose up -d
実行時、以下のエラーが吐かれるので解決したい
前提
DockerでLaravel開発環境を構築しようとしていたところ発生しました。
実行環境
- win11
- Ubuntu
- docker v24.0.2
- docker compose v2.18.1
ファイル構造
laravel_docker
├── compose.yml
└── docker
├── nginx
│ └── default.conf
└── php
├── Dockerfile
└── php.ini
発生している問題・エラーメッセージ
parsing laravel_docker/compose.yml: yaml: unmarshal errors:
line 9: mapping key "container_name" already defined at line 3
line 20: mapping key "container_name" already defined at line 3
line 12: mapping key "volumes" already defined at line 5
line 28: mapping key "volumes" already defined at line 5
line 45: mapping key "volumes" already defined at line 5
line 19: mapping key "image" already defined at line 8
line 35: mapping key "image" already defined at line 8
line 20: mapping key "container_name" already defined at line 9
line 32: mapping key "ports" already defined at line 10
line 43: mapping key "ports" already defined at line 10
line 28: mapping key "volumes" already defined at line 12
line 45: mapping key "volumes" already defined at line 12
line 35: mapping key "image" already defined at line 19
line 36: mapping key "environment" already defined at line 21
line 45: mapping key "volumes" already defined at line 28
line 43: mapping key "ports" already defined at line 32
該当のソースコード
services:
app:
container_name: app
build: ./docker/php
volumes:
- .:/var/www
nginx:
image: nginx
container_name: nginx
ports:
- 8000:80
volumes:
- .:/var/www
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
working_dir: /var/www
depends_on:
- app
db:
image: mysql:5.7
container_name: db
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: database
MYSQL_USER: db-user
MYSQL_PASSWORD: db-pass
TZ: 'Asia/Tokyo'
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode
_ci
volumes:
- ./docker/db/data:/var/lib/mysql
- ./docker/db/my.cnf:/etc/mysql/conf.d/my.cnf
- ./docker/db/sql:/docker-entrypoint-initdb.d
ports:
- 3306:3306
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
- PMA_ARBITRARY=1
- PMA_HOST=db
- PMA_USER=root
- PMA_PASSWORD=password
links:
- db
ports:
- 8080:80
volumes:
- /sessions
試したこと
https://github.com/fluxcd/helm-controller/issues/286
https://github.com/docker/compose/issues/10411
https://github.com/kasmtech/workspaces-issues/issues/350
上記リンクにたどり着きましたがイマイチつかめずわからないままです。