dotronglong / faker

A fake api server built in Java
38 stars 6 forks source link

Constantly getting 400 with docker #50

Closed fchris82 closed 1 year ago

fchris82 commented 1 year ago

docker-compose.yml

  test_api:
    image: dotronglong/faker:stable
    volumes:
      - ${PWD}/tests/Resources/api:/app/mocks

test.json

{
  "plugins": [
    {
      "name": "list",
      "args": {
        "count": 5,
        "item": {
          "id": "#random:int:min=1&max=1000#",
          "name": "#random:name#",
          "created_at": "#timestamp#",
          "updated_at": "#timestamp#"
        }
      }
    },
    {"name": "random"},
    {"name": "timestamp"}
  ],
  "request": {
    "method": "GET",
    "path": "/v1/users"
  },
  "response": {
    "body": []
  }
}

simple.json

{
  "request": {
    "method": "GET",
    "path": "/api/v1/simp"
  },
  "response": {
    "body": "simp"
  }
}

Log:

test_api_1            | 
test_api_1            |   .   ____          _            __ _ _
test_api_1            |  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
test_api_1            | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
test_api_1            |  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
test_api_1            |   '  |____| .__|_| |_|_| |_\__, | / / / /
test_api_1            |  =========|_|==============|___/=/_/_/_/
test_api_1            |  :: Spring Boot ::        (v2.2.4.RELEASE)
test_api_1            | 
test_api_1            | 2023-05-09 09:59:00.476  INFO 1 --- [           main] c.dotronglong.faker.FakerApplicationKt   : Starting FakerApplicationKt on b2e86a6c0afd with PID 1 (/app/faker.jar started by root in /)
test_api_1            | 2023-05-09 09:59:00.479  INFO 1 --- [           main] c.dotronglong.faker.FakerApplicationKt   : No active profile set, falling back to default profiles: default
test_api_1            | 2023-05-09 09:59:01.564  INFO 1 --- [           main] c.d.faker.service.router.JsonRouter      : Parsed file test.json
test_api_1            | 2023-05-09 09:59:01.565  INFO 1 --- [           main] c.d.faker.service.router.JsonRouter      : Parsed file simple.json
test_api_1            | 2023-05-09 09:59:01.566  INFO 1 --- [           main] c.d.faker.service.router.JsonRouter      : Scanning is completed.
test_api_1            | 2023-05-09 09:59:01.566  INFO 1 --- [           main] c.d.faker.service.router.JsonRouter      : Version: 2.1.7
test_api_1            | 2023-05-09 09:59:02.342  INFO 1 --- [           main] o.s.b.web.embedded.netty.NettyWebServer  : Netty started on port(s): 3030
test_api_1            | 2023-05-09 09:59:02.344  INFO 1 --- [           main] c.dotronglong.faker.FakerApplicationKt   : Started FakerApplicationKt in 2.169 seconds (JVM running for 2.569)

Curl test:

curl -v http://test_api:3030/v1/users
*   Trying 172.18.0.78:3030...
* Connected to test_api (172.18.0.78) port 3030 (#0)
> GET /v1/users HTTP/1.1
> Host: test_api:3030
> User-Agent: curl/7.69.1
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< content-length: 0
< 
* Connection #0 to host test_api left intact

The simple test is the same. Do you have any idea what is wrong?

dotronglong commented 1 year ago

Hi did you try to expose the ports? Can you try to use inspect command to see more information of docker instance?

fchris82 commented 1 year ago

I do not have to expose them, I call it from another container, and it can see the fake API container. I am pretty sure about it.

Meantime, I looked for another fake API docker image, and I use that one because there is currently time pressure. But thank you for the answer, maybe it is only an unusual problem only at me.

hyamanieu commented 1 year ago

@dotronglong I believe you shoudl reopen this issue. We have the same problem where using docker DHCP doesn't work but calling from the host does work.

dotronglong commented 1 year ago

hi @hyamanieu , thanks for your comment, I tried to test and here is the result. Since I don't have problem with it, I don't know what happened at your end, could you help to share your issue, so we can work together. For now I will reopen this issue for discussing potential issue.

https://github.com/dotronglong/faker/assets/6072939/0f98a40d-8fd6-4491-9da5-c97771d0adf9

Additionally, I did notice that I haven't updated the version of docker, but it should not cause any problems.

hyamanieu commented 1 year ago

@dotronglong thanks for your trial. You're trying to curl from your host using localhost: this works fine.

What doesn't work is using curl from another container within the same network, see response from OP.

he calls curl -v http://test_api:3030/v1/users from another container, not curl -v http://localhost:3030/v1/users

From another container, using the IP address works fine, only using container name doesn't work.

dotronglong commented 1 year ago

@hyamanieu Perhaps I missed that part, I would need to ask for more information, however, I remember that in order to have name mapping for hostname, they must be under same network. Could you share to me your whole docker compose files so I can check more on that? From my point of view, I think it is not something we could do with this application.

dotronglong commented 1 year ago

Close due to not having enough information. Please reopen if you found it necessary.

hyamanieu commented 1 year ago

I will try to work on an minimal example and reopen then