dockerdocker-composeteamcity

Docker Compose "volumes Additional property is not allowed" or "volumes must be a mapping"


I am using Maven to interpolate a docker compose file, in order to map the working directory in either Linux and Windows. Interpolation works as intended on both OSs. In my local Windows environment, when running "docker compose up" I get both containers with the mapped volume (which already exists on the host machine), without specifying "volumes: " at top-level, only at service-level.

However, if I try to run the same setup in linux-based TeamCity, I get the following message "service "job_controller" refers to undefined volume path/to/target/classes: invalid compose project"

After checking others' answers from here, I've understood that I also have to specify "volumes:" at top-level, which I did at the bottom of the compose file.

Now, I am prompted with "volumes Additional property /opt/buildagent/work/9857567c5e342350/path/to/target/classes is not allowed"

name: Distributed
services:
  create_database:
    container_name: create_database
    command:
    - ./script.sh
    - deployer
    - -f
    - ../config/product-mssql-v11.manifest.yaml
    - drop-create-database-properties
    image: alpine-3-corretto-11-wildfly-11.11.0-SNAPSHOT
    networks:
    - deploy
    volumes:
    - C:\\SourceCode\\Path\\to\\target/classes:/opt/product/config
    healthcheck:
     test: ["CMD", "/opt/product/script.sh", "deployer", "-f", "/opt/product/config/product-mssql-v11.manifest.yaml", "healthy"]
     interval: 20s
     timeout: 60s
     retries: 5

  job_controller:
    container_name: job_controller
    environment:
      DEPLOYMENT_MANIFEST: /opt/product/config/main.manifest.yaml
      PROPERTIES_FILE_NAME: /opt/product/config/risk-wildfly.properties
      JAVA_OPTS: "-Xms1g -Xmx4g -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=1g -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true"
    ports:
    - 8080:8080
    image: alpine-3-corretto-11-wildfly-11.11.0-SNAPSHOT
    volumes:
    - C:\\SourceCode\\Path\\to\\target/classes:/opt/product/config
    networks:
    - deploy
    depends_on:
      create_database:
        condition: service_completed_successfully
    restart: on-failure
    healthcheck:
     test: ["CMD", "/opt/product/script.sh", "health-check", "--context-path","product"]
     interval: 20s
     timeout: 60s
     retries: 5      

networks:
 deploy:
    name: deploy
    external: true
    
volumes:
  C:\\SourceCode\\Path\\to\\target/classes:
    external: true

Now, locally, if I try to run "docker compose up" with the "volumes: " specified at the bottom I get as well the same "volumes Additional property C:\SourceCode\Path\to\target/classes is not allowed"

If, instead of

volumes:
      C:\\SourceCode\\Path\\to\\target/classes:
        external: true

I use

volumes:

I get the "volumes: " must be a mapping. So neither of this works.

C:\>docker compose version
Docker Compose version v2.10.2

C:\>docker-compose version
docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1g  21 Apr 2020

C:\>docker version
Client:
 Cloud integration: v1.0.29
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:09:02 2022
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.12.0 (85629)
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:01:23 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

How can I run this successfully in both OSs considering the volume mapping?


Solution

  • If you want to map specific folder from host to docker container you don't need root section

    volumes:
    

    at all

    It's used to create named volumes somewhere inside docker and reference them by name in volumes section of service definition (and across multiple docker-compose files if external flag is set)