paulo
paulo

Reputation: 41

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

Upvotes: 1

Views: 793

Answers (2)

lemario
lemario

Reputation: 596

I had the same issue and it was because of invalid characters. My image name was keycloak_blog. I changed it to keycloakblog and it started to work

Upvotes: 1

queeg
queeg

Reputation: 9384

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).

Upvotes: 1

Related Questions