Search code examples
dockerdocker-composesparqldocker-machinevirtuoso

HttpException: -404 Failed to connect to remote server on mac while running Docker


I am getting Error HttpException: -404 Failed to connect to remote server while running jar file from docker execute a command docker exec -it Test_docker java -jar TestDocker.jar.

Note: I have created docker on windows, Where my docker machine IP is 192.168.99.100 and my docker exec command running successfully.I am accessing SPARQL endpoint on windows using URL: http://192.168.99.100:8890/sparql this will work perfectly. But when I am using same on mac it will give me an error which I mention above. I have also try to change SPARQL endpoint on my code as http://localhost:8890/sparql but not work well though it will work fine on chrome browser on mac while executing through command it will giving me an error.

Here my docker-compose file,

version: "3"
services:
  jardemo_test:
    container_name: Test_docker
    image: "java:latest"
    working_dir: /usr/src/myapp
    volumes:
      - /docker/test:/usr/src/myapp    
    tty: true
    depends_on:
      - virtuoso

  virtuoso:
    container_name: virtuoso_docker
    image: openlink/virtuoso_opensource
    ports:
      - "8890:8890"
      - "1111:1111"
    environment:      
      DB_USER_NAME: dba
      DBA_PASSWORD: dba
      DEFAULT_GRAPH: http://localhost:8890/test
    volumes:
      - /docker/virtuoso-test/:/data

Note: I have tried all the way to set the environment variable on docker-compose file default graph URL with all the IP address but it won't allow.Which IP I have tried all combination listed below. Though I am getting the same error.

below is my docker-compose ps result,

 $ docker-compose ps
 Name                    Command               State                       Ports
---------------------------------------------------------------------------------------------------------
Test_docker      /bin/bash                        Up
virtuoso_docker   /opt/virtuoso-opensource/b ...   Up      0.0.0.0:1111->1111/tcp, 0.0.0.0:8890->8890/tcp

Below is my code which I am using,

QueryExecution qexec = QueryExecutionFactory.sparqlService("http://localhost:8890/sparql", queryString);
ResultSet results1 = qexec.execSelect();

Info: After running successful docker I have accessed the http://localhost:8890/sparql. it will successfully run on the mac.

Can anybody please help me to solve this issue?Also, welcome your suggestions and thought.Thanks for the help and your time in advance.


Solution

  • As per my colleague suggested, The problem is that the code in de docker file sees the docker as the local host. The IP-address 192.168.99.100 is also not known because mac doesn't have it. To solve the problem of connections, docker uses its own network.The docker-compose service names are used as the reference. So instead of using http://localhost:8890/sparql, you should use http://virtuoso:8890/sparql as virtuoso is the service name.

    I tried this and it will solve my problem.