HttpException:-404 无法连接到 mac 上的远程服务器,而 运行 Docker
HttpException: -404 Failed to connect to remote server on mac while running Docker
我得到 Error HttpException: -404 Failed to connect to remote server
而 运行 来自 docker 的 jar 文件执行命令 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.
这是我的 docker-compose 文件,
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.
- DEFAULT_GRAPH: http://localhost:8890/test
- DEFAULT_GRAPH: http://127.0.0.1:8890/test
- DEFAULT_GRAPH: http://0.0.0.0:8890/test
下面是我的 docker-compose ps
结果,
$ 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
下面是我正在使用的代码,
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.
有人可以帮我解决这个问题吗?另外,欢迎您提出建议,thought.Thanks 提前获得帮助和时间。
根据我同事的建议,问题是 docker 文件中的代码将 docker 视为本地主机。 IP-address 192.168.99.100 也不知道,因为 mac 没有。为了解决连接问题,docker使用自己的network.Thedocker-compose服务名称作为参考。因此,不要使用 http://localhost:8890/sparql, you should use http://virtuoso:8890/sparql,因为 virtuoso 是服务名称。
我试过了,它会解决我的问题。
我得到 Error HttpException: -404 Failed to connect to remote server
而 运行 来自 docker 的 jar 文件执行命令 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.
这是我的 docker-compose 文件,
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.
- DEFAULT_GRAPH: http://localhost:8890/test
- DEFAULT_GRAPH: http://127.0.0.1:8890/test
- DEFAULT_GRAPH: http://0.0.0.0:8890/test
下面是我的 docker-compose ps
结果,
$ 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
下面是我正在使用的代码,
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.
有人可以帮我解决这个问题吗?另外,欢迎您提出建议,thought.Thanks 提前获得帮助和时间。
根据我同事的建议,问题是 docker 文件中的代码将 docker 视为本地主机。 IP-address 192.168.99.100 也不知道,因为 mac 没有。为了解决连接问题,docker使用自己的network.Thedocker-compose服务名称作为参考。因此,不要使用 http://localhost:8890/sparql, you should use http://virtuoso:8890/sparql,因为 virtuoso 是服务名称。
我试过了,它会解决我的问题。