无法连接到公开的 Docker 端口
Cannot connect to exposed Docker port
我 运行 Docker 在 OS X 上使用最新的 Docker 工具箱。
Docker version 1.10.2, build c3959b1
docker-machine version 0.6.0, build e27fb87
docker-compose version 1.6.0, build d99cad6
我在容器中有一个 Java 应用程序,该容器是根据以下 Docker 文件构建的:
FROM <my internal registry>/java:8
ENTRYPOINT ["java", "-cp", "/var/app/scheduler/scheduler-jar-with-dependencies.jar", "com.myapp.scheduler.Application"]
和docker-compose.yml:
scheduler:
image: <my internal registry>/scheduler
command: -Dspring.profiles.active=local -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5050
environment:
TERM: xterm
ports:
- "4567:4567" # http port
- "5050:5050" # java debug port
volumes:
- $SCHEDULER_GIT_ROOT/target:/var/app/scheduler
- $LOG/scheduler:/var/log/scheduler
启动容器时,我可以使用虚拟机 IP (192.168.99.100:4567) 从浏览器访问 http 端口。但是,我无法将调试器连接到调试端口,也无法通过 telnet 访问该端口,无论我将端口更改为什么。 docker ps
产量:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9395e0f20dd5 <my registry>/scheduler "java -cp /var/app/sc" 7 minutes ago Up 7 minutes 0.0.0.0:4567->4567/tcp, 0.0.0.0:5050->5050/tcp scheduler_scheduler_1
有人知道为什么我可以连接到一个端口,而不能连接到另一个端口吗?
编辑:这是来自 docker inspect
的命令:
"Path": "java",
"Args": [
"-cp",
"/var/app/scheduler/scheduler-jar-with-dependencies.jar",
"com.mlbam.cms.scheduler.Application",
"-Dspring.profiles.active=local",
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5050"
]
这最终与 Docker 无关,而是与我 运行 java 命令的方式有关。调试参数必须在 -cp:
之前
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5050 -cp /var/app/scheduler/scheduler-jar-with-dependencies.jar com.myapp.scheduler.Application
我 运行 Docker 在 OS X 上使用最新的 Docker 工具箱。
Docker version 1.10.2, build c3959b1
docker-machine version 0.6.0, build e27fb87
docker-compose version 1.6.0, build d99cad6
我在容器中有一个 Java 应用程序,该容器是根据以下 Docker 文件构建的:
FROM <my internal registry>/java:8
ENTRYPOINT ["java", "-cp", "/var/app/scheduler/scheduler-jar-with-dependencies.jar", "com.myapp.scheduler.Application"]
和docker-compose.yml:
scheduler:
image: <my internal registry>/scheduler
command: -Dspring.profiles.active=local -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5050
environment:
TERM: xterm
ports:
- "4567:4567" # http port
- "5050:5050" # java debug port
volumes:
- $SCHEDULER_GIT_ROOT/target:/var/app/scheduler
- $LOG/scheduler:/var/log/scheduler
启动容器时,我可以使用虚拟机 IP (192.168.99.100:4567) 从浏览器访问 http 端口。但是,我无法将调试器连接到调试端口,也无法通过 telnet 访问该端口,无论我将端口更改为什么。 docker ps
产量:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9395e0f20dd5 <my registry>/scheduler "java -cp /var/app/sc" 7 minutes ago Up 7 minutes 0.0.0.0:4567->4567/tcp, 0.0.0.0:5050->5050/tcp scheduler_scheduler_1
有人知道为什么我可以连接到一个端口,而不能连接到另一个端口吗?
编辑:这是来自 docker inspect
的命令:
"Path": "java",
"Args": [
"-cp",
"/var/app/scheduler/scheduler-jar-with-dependencies.jar",
"com.mlbam.cms.scheduler.Application",
"-Dspring.profiles.active=local",
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5050"
]
这最终与 Docker 无关,而是与我 运行 java 命令的方式有关。调试参数必须在 -cp:
之前java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5050 -cp /var/app/scheduler/scheduler-jar-with-dependencies.jar com.myapp.scheduler.Application