私は2つのSpring Webサービスを持っており、httpで通信する必要があります。どちらも私のマシン上でopenjdk:8-jre-alpine上のdcokerコンテナで実行されています。ここで「接続が拒否した」で失敗POSTクエリされる:「私は単にrun -p 8080:8080
で両容器を実行しているドッカーコンテナの通信はhttp:
@RequestMapping(
path = "create",
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<Long> create(@RequestParam("playerCount") int playerCount) {
long gameId = gameService.create(playerCount);
HttpHeaders headers = new HttpHeaders();
headers.add("Access-Control-Allow-Origin", "*");
return new ResponseEntity<>(gameId, headers, HttpStatus.OK);
}
と:
public String createPost(int playerCount) {
String uri = URI + "/create";
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(uri)
.queryParam("playerCount", playerCount);
HttpEntity<?> entity = new HttpEntity<>(headers);
ResponseEntity<String> response = rest.exchange(
builder.build().encode().toUri(),
HttpMethod.POST,
entity,
String.class);
logger.info("Create request");
return response.getBody();
}
URIがここhttp://localhost:8090/game
では、他のサービスのコントローラーに対応しています8090:8090 '。そして、私が以前に言ったように、「接続が拒否されました」。通信を正しく設定する方法は?
注: Intellijで実行すると正常に動作します。
私はこれを見てきました[このSOポスト](https://stackoverflow.com/questions/19897743/exposing-a-port-on-a-live-docker-container) – DevDio