简体   繁体   中英

Make HTTP request from one container to another

I am trying to do a httpRequest from library to people-service, but not that i've tried works. i saw that if use the name it shoud ork, so i have tried http://library:8080, but it returns the error

java.lang.IllegalArgumentException: unsupported URI

Here is my Dockerfile:

FROM openjdk:11-jdk-slim
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

and my docker-compose:

version: '3.5'

services:
  library:
    build:
      context: ./
    ports:
      - "8081:8081"
    networks:
      - library-network
    restart: on-failure

  mysql-service:
    image: mysql:5.7
    ports:
    - "3306:3306"
    networks:
      - library-network
    environment:
      - MYSQL_ROOT_PASSWORD=admin
      - MYSQL_USER=admin
      - MYSQL_PASSWORD=admin
      - MYSQL_DATABASE=bootdb
    restart: on-failure

  people-service:
    build:
      context: ./
      args:
        JAR_FILE: ./target/library.jar
    ports:
      - "8080:8080"
    environment:
      - DB_HOST=jdbc:mysql://mysql-service:3306/library
    networks:
      - library-network
    depends_on:
      - mysql-service
      - library
    restart: on-failure

networks:
  library-network:
    driver: bridge

Your question says: I am trying to do a httpRequest from library to people-service

From that I assume the request would be initiated in library . Then the URL should look like http://people-service:8080 . But from the error message I'd assume your library is not able to run http requests - regardless of where they are going to, which is a bit strange. Investigate on that first, using simple urls like http://stackoverflow.com (which will return http status 301).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM