docker-compose.yml 文件中 运行 PGAdmin 的问题

Problem with run PGAdmin in docker-compose.yml file

我有一个 docker-compose.yml:

 version: "3.9"
     
 services:
   db:
     image: postgres
     volumes:
       - ./data/db:/var/lib/postgresql/data
       - ./mysqlfile.sql:/docker-entrypoint-initdb.d/mysqlfile.sql
     environment:
       - POSTGRES_DB=postgres
       - POSTGRES_USER=postgres
       - POSTGRES_PASSWORD=postgres

   pgadmin:
     image: dpage/pgadmin4:4.18
     restart: always
     environment:
       - [PGADMIN_DEFAULT_EMAIL: admin@linuxhint.com]
       - [PGADMIN_DEFAULT_PASSWORD: secret]
       - [PGADMIN_LISTEN_PORT: 80]
     ports:
       - "8090:80"
     volumes:
       - pgadmin-data:/var/lib/pgadmin
     links:
       - "db:pgsql-server"
     volumes:
 
   web:
     build: .
     command: python manage.py runserver 0.0.0.0:8000
     volumes:
       - .:/code
     ports:
       - "8000:8000"
     depends_on:
       - db

当我尝试使用 docker-compose up 命令时出现如下错误:

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.pgadmin.volumes contains an invalid type, it should be an array

当我从 pgadmin 部分删除第二个 volumes 时出现新错误:

Named volume "pgadmin-data:/var/lib/pgadmin:rw" is used in service "pgadmin" but no declaration was found in the volumes section.

如何正确修复此错误 运行 我的容器?

您在 pgadmin 中定义了两次 volumes,删除空的。然后在底部声明:

...
  ports:
    - "8090:80"
  volumes:
    - pgadmin-data:/var/lib/pgadmin
  links:
    - "db:pgsql-server"
volumes:
  pgadmin-data:

请注意 volumes: 不像 links:

那样缩进