无法连接到暴露的Docker端口

时间:2016-03-03 03:36:08

标签: java docker boot2docker docker-compose docker-machine

我使用最新的Docker Toolbox在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

我在一个使用以下Dockerfile构建的容器中有一个Java应用程序:

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

当我打开容器时,我可以使用VMs 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"
] 

1 个答案:

答案 0 :(得分:1)

这与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