Mockoon Docker compose : Error: Missing required flag

2.4k Views Asked by At

I'm trying to run mockoon docker cli using docker compose for my mock api and i have the json exported to my directory,

version: "3"
services:
  mockoon:
    image: mockoon/cli:latest
    command: mockoon-cli start
    networks:
      demo:
    ports:
      - "8001:8001"
    volumes:
      - type: bind
        source: ./mock.json
        target: /www
networks:
  demo:

when i run docker-compose up the container comes up for few seconds and shuts down with the following log

 ›   Error: Missing required flag:
 ›    -d, --data DATA  Path(s) or URL(s) to your Mockoon data file(s)
 ›   See more help with --help

Any additional settings that i should make or i have missed something in my config.

4

There are 4 best solutions below

1
Pavol Krajkovič On BEST ANSWER

I have checked the official documentation, you need to specify the --data directory inside the docker-compose command line.

So the compose file would like like this:


version: "3"
services:
  mockoon:
    image: mockoon/cli:latest
    command: mockoon-cli start  --data <directory> # this is where the change takes place
    networks:
      demo:
    ports:
      - "8001:8001"
    volumes:
      - type: bind
        source: ./mock.json
        target: /www
networks:
  demo:

mockoon cli

0
shellyyg On

The "data" after the --data flag is the alias to the file name, not the folder name. Hence, it should be:

version: "3"
services:
  chicargo-mockoon-mock:
    platform: linux/amd64
    image: mockoon/cli:latest
    ports:
      - "8001:8001"
    volumes:
      - type: bind
        source: ./your-file-name.json
        target: /data
    command: mockoon-cli start  --data data
0
Yevhen Yermolenko On

Faced with the similar problem and found that:

  1. It's better to link environment as a data rather than swagger file for better experience with mockoon lib.
  2. Do not include mockoon-cli start to the command: as it is already included in the ENTRYPOINT. This works for me:
version: "3"
 services:
   mockoon-mock:
     image: mockoon/cli
     command: ["--data", "data"]
     ports:
       - "8001:8001"
     volumes:
       - ./myFolder/myEnvironmentFile.json:/data

Documentation

0
Ali Darvish On

I also encountered this issue, and after extensive searching, I came across these results:

  1. You need too provide a .json or .yaml file as an open API specification that has info about your API mock data. See this json example below:
{
  "swagger": "2.0",
  "info": { "title": "Sample API", "version": "1.0.0" },
  "paths":
    {
      "/users":
        {
          "get":
            {
              "summary": "Retrieve all users",
              "operationId": "getUsers",
              "responses":
                {
                  "200":
                    {
                      "description": "Successful operation",
                      "schema":
                        { "type": "array", "items": { "type": "string" } }
                    }
                }
            }
        },
      "/users/{id}":
        {
          "get":
            {
              "summary": "Get a user by ID",
              "operationId": "getUserById",
              "parameters":
                [
                  {
                    "name": "id",
                    "in": "path",
                    "required": true,
                    "type": "integer",
                    "format": "int64"
                  }
                ],
              "responses":
                {
                  "200":
                    {
                      "description": "Successful operation",
                      "schema":
                        {
                          "type": "object",
                          "properties":
                            {
                              "id": { "type": "integer", "format": "int64" },
                              "name": { "type": "string" }
                            }
                        }
                    }
                }
            }
        }
    }
}
  1. As you see in compose.yaml example below, you have to only set --data flag and no need for mockoon-cli or start command. Also when you are setting volume property you should address to .json or .yaml file and not only the directory.
version: '3.8'
services:
  mockoon:
    image: mockoon/cli:latest
    command: [ "--data", "/openapi/openapi.json" ]
    ports:
      - 3000:3000
    volumes:
      - ./openapi-specification.json:/openapi/openapi.json

This worked for me. I hope it's helpful for you as well.