我已经部署了两个Docker容器,其中托管着两个REST服务,在Jetty中进行部署。
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端口,但没有成功。
service2
在容器内使用URLhttp://localhost:7070/service1/hello
调用service1
,这是行不通的,因为localhost
只托管了service2
。您将service2
容器连接到了service1
,所以请尝试改用http://service1:7070/service1/hello
。您可以阅读有关容器链接的更多信息以了解原因。 - Nicolas