I'm facing an issue with my Docker Compose setup, and I'm trying to conditionally create a volume based on the value of the SRC_VOLUME environment variable in my docker-compose.yml file. However, when I set SRC_VOLUME=true in my .env file, I encountered the following error message:
services.test.volumes.0 type is required
Here are my Docker Compose file and .env file contents for reference:
Docker Compose file (docker-compose.yml):
version: "3.8"
services:
  test:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ${SRC_VOLUME:-false}:
        - ./src:/code
.env file contents (.env):
# Source Code Volume
SRC_VOLUME=true
I expect that when SRC_VOLUME is set to true in my .env file, it should create a volume for the ./src directory. However, I'm encountering the mentioned error. What could be causing this error, and how can I resolve it to conditionally create the volume as intended?
