Одно и то же приложение не может отправить http-запрос docker compose - PullRequest
1 голос
/ 14 марта 2020

Пружинная загрузка

дооснащение 2

docker

в моем docker -компонентном файле:

version: "3"

services:
  server:
    image: asubscriber/eshop:1.0.1
    build: .
    ports:
      - 8090:8090
  1. Запустите мое приложение (Spring boot) из консоли следующим образом:

    java -jar build / libs / eshop-1.0.1.jar eshop-1.0.1.jar

Выполнить успешно. И успех на http запрос. Вот лог:

[INFO ] 2020-03-14 21:41:09.480 [OkHttp http://localhost:8091/...] OkHttpClient - --> POST http://localhost:8091/api/v1/notifyEmail?emailTo=a_subscriber%40mail.ru&action=order_update&orderId=38 http/1.1
[INFO ] 2020-03-14 21:41:09.480 [OkHttp http://localhost:8091/...] OkHttpClient - Content-Length: 0
[INFO ] 2020-03-14 21:41:09.480 [OkHttp http://localhost:8091/...] OkHttpClient - 
[INFO ] 2020-03-14 21:41:09.481 [OkHttp http://localhost:8091/...] OkHttpClient - 
[INFO ] 2020-03-14 21:41:09.481 [OkHttp http://localhost:8091/...] OkHttpClient - --> END POST (0-byte body)
[INFO ] 2020-03-14 21:41:12.732 [OkHttp http://localhost:8091/...] OkHttpClient - <-- 200  http://localhost:8091/api/v1/notifyEmail?emailTo=a_subscriber%40mail.ru&action=order_update&orderId=38 (3250ms)
[INFO ] 2020-03-14 21:41:12.732 [OkHttp http://localhost:8091/...] OkHttpClient - Content-Type: application/json
[INFO ] 2020-03-14 21:41:12.732 [OkHttp http://localhost:8091/...] OkHttpClient - Transfer-Encoding: chunked
[INFO ] 2020-03-14 21:41:12.732 [OkHttp http://localhost:8091/...] OkHttpClient - Date: Sat, 14 Mar 2020 19:41:12 GMT
[INFO ] 2020-03-14 21:41:12.733 [OkHttp http://localhost:8091/...] OkHttpClient - Keep-Alive: timeout=60
[INFO ] 2020-03-14 21:41:12.733 [OkHttp http://localhost:8091/...] OkHttpClient - Connection: keep-alive
[INFO ] 2020-03-14 21:41:12.734 [OkHttp http://localhost:8091/...] OkHttpClient - 
[INFO ] 2020-03-14 21:41:12.734 [OkHttp http://localhost:8091/...] OkHttpClient - {"code":0,"message":"Success"}

Ницца. Это нормально работает. Успешно отправьте запрос POST http.

Теперь я запускаю ЖЕ МОЕ приложение от docker compose

docker - составить

Успешно запустить приложение , Но если я хочу создать http-запрос, я получаю сообщение об ошибке:

Failed to connect to localhost/127.0.0.1:8091


server_1  | [INFO ] 2020-03-14 19:37:29.526 [OkHttp http://localhost:8091/...] OkHttpClient - --> POST http://localhost:8091/api/v1/notifyEmail?emailTo=a_subscriber%40mail.ru&action=order_update&orderId=4 http/1.1
server_1  | [INFO ] 2020-03-14 19:37:29.527 [OkHttp http://localhost:8091/...] OkHttpClient - Content-Length: 0
server_1  | [INFO ] 2020-03-14 19:37:29.527 [OkHttp http://localhost:8091/...] OkHttpClient - 
server_1  | [INFO ] 2020-03-14 19:37:29.527 [OkHttp http://localhost:8091/...] OkHttpClient - 
server_1  | [INFO ] 2020-03-14 19:37:29.527 [OkHttp http://localhost:8091/...] OkHttpClient - --> END POST (0-byte body)
server_1  | [DEBUG] 2020-03-14 19:37:29.529 [http-nio-8090-exec-5] SQL - select user0_.id as id1_3_, user0_.active as active2_3_, user0_.created as created3_3_, user0_.password as password4_3_, user0_.updated as updated5_3_, user0_.username as username6_3_ from usr user0_ where user0_.username=?
server_1  | [DEBUG] 2020-03-14 19:37:29.530 [http-nio-8090-exec-5] SQL - select roles0_.user_id as user_id1_2_0_, roles0_.role as role2_2_0_ from user_roles roles0_ where roles0_.user_id=?
server_1  | [DEBUG] 2020-03-14 19:37:29.530 [http-nio-8090-exec-5] SQL - select orders0_.user_id as user_id7_1_0_, orders0_.id as id1_1_0_, orders0_.id as id1_1_1_, orders0_.category_id as category6_1_1_, orders0_.created as created2_1_1_, orders0_.description as descript3_1_1_, orders0_.name as name4_1_1_, orders0_.updated as updated5_1_1_, orders0_.user_id as user_id7_1_1_ from orders orders0_ where orders0_.user_id=?
server_1  | [DEBUG] 2020-03-14 19:37:29.531 [http-nio-8090-exec-5] SQL - select orders0_.id as id1_1_, orders0_.category_id as category6_1_, orders0_.created as created2_1_, orders0_.description as descript3_1_, orders0_.name as name4_1_, orders0_.updated as updated5_1_, orders0_.user_id as user_id7_1_ from orders orders0_ where orders0_.user_id=?
server_1  | [DEBUG] 2020-03-14 19:37:29.536 [http-nio-8090-exec-5] SQL - select category0_.id as id1_0_0_, category0_.created as created2_0_0_, category0_.description as descript3_0_0_, category0_.name as name4_0_0_, category0_.updated as updated5_0_0_, orders1_.id as id1_1_1_, orders1_.category_id as category6_1_1_, orders1_.created as created2_1_1_, orders1_.description as descript3_1_1_, orders1_.name as name4_1_1_, orders1_.updated as updated5_1_1_, orders1_.user_id as user_id7_1_1_, user2_.id as id1_3_2_, user2_.active as active2_3_2_, user2_.created as created3_3_2_, user2_.password as password4_3_2_, user2_.updated as updated5_3_2_, user2_.username as username6_3_2_, roles3_.user_id as user_id1_2_3_, roles3_.role as role2_2_3_ from category category0_ left outer join orders orders1_ on category0_.id=orders1_.category_id left outer join usr user2_ on orders1_.user_id=user2_.id left outer join user_roles roles3_ on user2_.id=roles3_.user_id where category0_.id=?
server_1  | [INFO ] 2020-03-14 19:37:29.538 [OkHttp http://localhost:8091/...] OkHttpClient - <-- HTTP FAILED: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:8091
server_1  | [ERROR] 2020-03-14 19:37:29.539 [OkHttp http://localhost:8091/...] DefaultRestClientCallback - onFailure: Error: Failed to connect to localhost/127.0.0.1:8091
server_1  | java.net.ConnectException: Failed to connect to localhost/127.0.0.1:8091
server_1  |     at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:265) ~[okhttp-3.14.4.jar!/:?]
server_1  |     at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:183) ~[okhttp-3.14.4.jar!/:?]
server_1  |     at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:224) ~[okhttp-3.14.4.jar!/:?]
server_1  |     at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:108) ~[okhttp-3.14.4.jar!/:?]

Почему это же приложение не работает с docker?

1 Ответ

1 голос
/ 14 марта 2020

добавьте это к вашей службе в docker -компонентном файле (только сетевая часть)

version: "3"

services:
  server:
    image: asubscriber/eshop:1.0.1
    build:
      context: .

    network_mode: "host"

    expose:
        - 9080

Это ответ, чтобы просто заставить его работать, лучше прочитать это , как отметил Сергей Петунин в комментариях выше.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...