Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从另一个容器调用docker容器_Docker_Jetty_Docker Compose_Dockerfile_Microservices - Fatal编程技术网

从另一个容器调用docker容器

从另一个容器调用docker容器,docker,jetty,docker-compose,dockerfile,microservices,Docker,Jetty,Docker Compose,Dockerfile,Microservices,我已经部署了两个docker容器,其中托管了部署在Jetty中的两个REST服务 Container 1 hosts service 1 and it Listens to 7070 Container 2 hosts service 2 and it Listens to 9090 端点:- service1: /ping /service1/{param} service2: /ping /service2/callService1 curl -X GET http://localh

我已经部署了两个docker容器,其中托管了部署在Jetty中的两个REST服务

Container 1 hosts service 1 and it Listens to 7070
Container 2 hosts service 2 and it  Listens to 9090
端点:-

service1:
/ping
/service1/{param}

service2:
/ping
/service2/callService1

curl -X GET http://localhost:7070/ping [Works]
curl -X GET http://localhost:7070/service1/hello [Works]
curl -X GET http://localhost:9090/ping [Works]
我已将容器配置为:

http://localhost:9090/serivce2/callService1 
calls 
http://localhost:7070/service1/hello
这会引发连接被拒绝异常。这是我的配置

docker-compose.yml
------------------
service1: 
  build: microservice/
  ports: 
    - "7070:7070"
  expose:
    - "7070"
service2:
 build: microservice_link/
 ports:
 - "9090:9090"
 expose: 
 - "9090"
 links:
 - service1

service1 Dockerfile
-------------------
FROM localhost:5000/java:7
COPY ./target/service1.jar /opt
WORKDIR /opt
ENTRYPOINT ["java", "-jar", "service1.jar","7070"]
CMD [""]

service2 Dockerfile
-------------------
FROM localhost:5000/java:7
COPY ./target/service2.jar /opt
WORKDIR /opt
ENTRYPOINT ["java", "-jar", "service2.jar","9090"]
CMD [""]

docker info
-----------
root@LT-NB-108U:~# docker info
Containers: 3
 Running: 2
 Paused: 0
 Stopped: 1
Images: 12
Server Version: 1.10.1
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 28
 Dirperm1 Supported: false
Execution Driver: native-0.2
Logging Driver: json-file
Plugins: 
 Volume: local
 Network: null host bridge
Kernel Version: 3.13.0-48-generic
Operating System: Ubuntu precise (12.04.5 LTS)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 3.47 GiB
Name: LT-NB-108U
ID: BS52:XURM:3SD7:TC3R:7YVA:ZBZK:CCL2:7AVC:RNZV:RBGW:2X2T:7C46
WARNING: No swap limit support
root@LT-NB-108U:~# 
问题:-

我正在尝试从容器2访问部署在容器1中的端点。然而,我得到一个连接被拒绝的异常。 我试图暴露容器2中的端口7070。那没用

curl http://service1:7070/ 
使用-
host1\u名称:host1的内部\u端口

该主机在container2中称为“service1”。将其用作主机名,端口是service1容器中的内部端口侦听器


如果service1上有express server,请在端口7070上侦听。

service2
正在使用URL从容器内调用
service1
http://localhost:7070/service1/hello
?这无法工作,
localhost
仅承载
service2
。您已将
service2
容器链接到
service1
,因此请尝试使用
http://service1:7070/service1/hello
。您可以阅读更多关于了解原因的内容。您的问题不是问题(-: