如何获取服务的端口号-Docker Compose文件 [英] How to get the port numbers for a service - Docker compose file

查看:195
本文介绍了如何获取服务的端口号-Docker Compose文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用docker-compose.yml启动容器。我正在尝试启动两项服务,一项是 mongo ,另一项是 OHIF查看器

I am trying to start containers with the docker-compose.yml. I am trying to start two services, one is mongo and other is OHIF viewer.

目前,我可以可以在本地访问mongo(在桌面上访问localhost:27017(端口转发之后),而无法使用OHIF查看器(端口不可见/空,因此我无法在本地访问它们)。能否指导我我可以设置它们吗?

Currently I am able to access mongo locally (localhost:27017(after port-forwarding) in desktop whereas OHIF viewer isn't possible (ports aren't visible/empty so, I am not able to access them locally). Can you guide me as to how I can set them?

您可以

基于我的json文件,从我的docker-compose文件中,我还设置了network_mode: host也可以在本地访问它们。我以为端口已设置(pacsIP:8042),但如上屏幕快照所示,当我执行 docker ps命令时缺少该端口。您能指导我吗?我是docker的新手,您的输入内容肯定会有所帮助。是我的Docker主机(远程lin ux服务器)的IP。我想将它们移植并在我的桌面上查看

Based on my json file, I thought the port was already set (pacsIP:8042) but it's missing as shown in screenshot above when I execute "docker ps" command. Can you guide me on this? I am new to docker and your inputs will definitely be helpful. PACSIP is my docker host (remote linux server) IP. I would like to port forward them and view it in my desktop

请在 docker-compose.yml 文件

version: '3.6'
   services:
     mongo:
       image: "mongo:latest"
    container_name: ohif-mongo
   ports:
     - "27017:27017"

   viewer:
     image: ohif/viewer:latest
      container_name: ohif-viewer
      ports:
        - "3030:80"
        - "8042:8042" - # Not sure whether this is correct. I tried with and without this as well but it didn't work
      network_mode: "host"   
      environment:
         - MONGO_URL=mongodb://mongo:27017/ohif
      extra_hosts:
          - "pacsIP:172.xx.xxx.xxx"
      volumes:
         - ./dockersupport-app.json:/app/app.json

如您所见,在卷中,我使用的是 dockersupport-app.json 文件以下

As you can see that in the volumes, I am using a dockersupport-app.json file which is given below

{
   "apps" : [{
   "name"        : "ohif-viewer",
    "script"      : "main.js",
    "watch"       : true,
    "merge_logs"  : true,
    "cwd"         : "/app/bundle/",
    "env": {
    "METEOR_SETTINGS": {
              "servers": {
                "dicomWeb": [
                                    {
                    "name": "Orthanc",
                    "wadoUriRoot": "http://pacsIP:8042/wado", # these ports 
                    "qidoRoot": "http://pacsIP:8042/dicom-web", #these ports
                    "wadoRoot": "http://pacsIP:8042/dicom-web", #these ports
                    "qidoSupportsIncludeField": false,
                    "imageRendering": "wadouri",
                    "thumbnailRendering": "wadouri",
                    "requestOptions": {
                      "auth": "orthanc:orthanc",
                      "logRequests": true,
                      "logResponses": false,

如何在本地访问OHIF-Viewer?我应该对docker-compose.yml或json文件进行哪些更改?我在docker-compose文件的端口部分下启用和不使用端口8042,但仍然无法正常工作。

How can I access the OHIF-Viewer locally? What changes should I make to docker-compose.yml or json file? I did with and without port 8042 under "Ports" section of docker-compose file but it didn't work still.

推荐答案

如果使用 network_mode:host ,它将绕过所有Docker标准联网。在这种情况下,包括端口映射:由于容器直接使用主机的网络接口,因此没有映射本身

If you use network_mode: host it bypasses all of Docker's standard networking. In this case that includes the port mappings: since the container is directly using the host's network interface, there's nothing to map per se.

network_mode:主机几乎没有必要,我在这里将其删除。那应该使端口在 docker ps 输出中再次可见,并使重新映射的端口3030可以访问。因为这样,您可能可以直接在主机网络上通过端口80(该服务可能绑定到该端口)访问服务。

network_mode: host is almost never necessary and I'd remove it here. That should make the ports visible in the docker ps output again, and make the remapped port 3030 accessible. As it is you can probably reach your service on port 80, which presumably the service binds to, directly on the host network.

这篇关于如何获取服务的端口号-Docker Compose文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆