dockerdocker-composecaddyfilestoplight

Copying files using Docker Compose


I am new to Docker Compose, and I was trying modify an example on serving multiple OpenAPI documents using Stoplight Prism. I have the file I want to copy under the directory /reference/Offers/Offers-APIs.v1.json, and in the project's root directory, I have a Dockerfile that copies the entire repository under /app. My question is, how to copy Offers-APIs.v1.json such that it is accessible in my docker-compose.yaml file?

My current attempt is this:

  prism_1:
    image: stoplight/prism:5  
      - ./reference/:/app/
    command: >
      mock -p 4010 --host 0.0.0.0 -d app/reference/Offers/Offers-APIs.v1.json

where the last line is a prism mock command that mocks my API. I attempt to copy the entire reference folder to /app directory, but when I run the program, it displays this error:

[7:07:46 PM] › [CLI] ✖  fatal     Error opening file "/usr/src/prism/packages/cli/app/reference/Offers/Offers-APIs.v1.json" 
2023-07-24T19:07:46.049079100Z ENOENT: no such file or directory, open '/usr/src/prism/packages/cli/app/reference/Offers/Offers-APIs.v1.json'

Solution

  • Following the getting started docs you should be able to start prism5 with these docker-compose file (I tried and it worked):

    version: '3.7'
    services:
      prism_1:
        image: stoplight/prism:5
        volumes:
          - ./Offers.yml:/tmp/Offers.yml:ro
        command: 'mock -p 4010 --host 0.0.0.0 -d /tmp/Offers.yml'
        ports:
          - '8080:4010'
    

    In my Offers.yml file i added the content of:

    https://github.com/stoplightio/prism/blob/master/examples/petstore.oas2.yaml

    You could try using your json file instead.