如何获取服务的端口号 - Docker 撰写文件 [英] How to get the port numbers for a service - Docker compose file
问题描述
我正在尝试使用 docker-compose.yml 启动容器.我正在尝试启动两个服务,一个是 mongo,另一个是 OHIF viewer.
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?
从我的 docker-compose 文件中可以看出,我已经设置了 network_mode:"host" 以便能够在我的桌面上本地访问它们.
As you can see from my docker-compose file that I have set network_mode:"host" to be able to access them locally in my desktop as well.
根据我的 json 文件,我认为端口已经设置(pacsIP:8042),但是当我执行docker ps"命令时,它丢失了,如上面的屏幕截图所示.你能指导我吗?我是 docker 新手,您的意见肯定会有所帮助.PACSIP 是我的 docker 主机(远程 linux 服务器)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: host
几乎从不需要,我会在这里删除它.这应该使端口在 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 撰写文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!