我一直在尝试使用docker-compose部署Jetty服务器,但我似乎无法从我的主机上获取我的应用程序端口。
这是我的compose.yml:
version: '3.3'
networks:
app-network:
services:
db:
image: postgres:alpine
command: postgres -c hba_file=/etc/pg_hba.conf
environment:
POSTGRES_USER: ******
POSTGRES_PASSWORD: ******
volumes:
- postgresVolume:/var/lib/postgresql/data
- ./pg_hba.conf:/etc/pg_hba.conf
networks:
app-network:
aliases:
- mydb
app:
build: .
restart: always
ports:
- "7001:7001"
depends_on:
- db
networks:
- app-network
volumes:
postgresVolume:
当我跑步时:
docker-compose up --build
一切都很好。但我似乎无法从我的主人那里访问我的api:
curl -H "Content-Type: application/json" -X POST -d '{"username":"user","password":"superPass"}' http://localhost:7001/user/ --trace-ascii ./dump
我明白了:
== Info: Trying ::1...
== Info: TCP_NODELAY set
== Info: Connected to localhost (::1) port 7001 (#0)
=> Send header, 136 bytes (0x88)
0000: POST /user/ HTTP/1.1
0016: Host: localhost:7001
002c: User-Agent: curl/7.58.0
0045: Accept: */*
0052: Content-Type: application/json
0072: Content-Length: 42
0086:
=> Send data, 42 bytes (0x2a)
0000: {"username":"user","password":"superPass"}
== Info: upload completely sent off: 42 out of 42 bytes
== Info: Empty reply from server
== Info: Connection #0 to host localhost left intact
运行
iptables -t nat -L -n
给出:
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- 172.17.0.0/16 0.0.0.0/0
MASQUERADE all -- 172.19.0.0/16 0.0.0.0/0
MASQUERADE all -- 172.18.0.0/16 0.0.0.0/0
MASQUERADE tcp -- 172.19.0.3 172.19.0.3 tcp
dpt:7001
Chain DOCKER (2 references)
target prot opt source destination
RETURN all -- 0.0.0.0/0 0.0.0.0/0
RETURN all -- 0.0.0.0/0 0.0.0.0/0
RETURN all -- 0.0.0.0/0 0.0.0.0/0
DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:7001 to:172.19.0.3:7001
编辑:
正在运行nmap localhost
Starting Nmap 7.60 ( https://nmap.org ) at 2018-02-08 12:09 CET
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000055s latency).
Other addresses for localhost (not scanned): ::1
Not shown: 998 closed ports
PORT STATE SERVICE
5432/tcp open postgresql
7001/tcp open afs3-callback
Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds
对我来说这两件事似乎都没问题。
docker-compose ps
似乎也是正确的:
Name Command State Ports
-----------------------------------------------------------------------------------
app_1 java -server -Xms2g -Xmx2g ... Up 0.0.0.0:7001->7001/tcp
db_1 docker-entrypoint.sh postg ... Up 5432/tcp
我的Jetty服务器似乎正在侦听正确的IP和端口:
2018-02-07 18:47:34.379 [main] INFO o.e.jetty.server.AbstractConnector - Started ServerConnector@62452cc9{HTTP/1.1,[http/1.1, h2c]}{0.0.0.0:7001}
有没有人知道我做错了什么?我正在运行Arch Linux,
docker-compose version
docker-compose version 1.18.0, build unknown
docker-py version: 2.7.0
CPython version: 3.6.4
OpenSSL version: OpenSSL 1.1.0g 2 Nov 2017
由于
答案 0 :(得分:0)
好吧...... Jetty对我来说是错误的。我没想到这一点,但只是将我的HTTP服务器实现更改为Netty解决了这个问题,而没有修改我的代码或配置。
也许我应该通知Jetty这个?