问题
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.
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?
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.
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
Please find below the docker-compose.yml file
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
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,
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.
回答1:
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
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.
回答2:
Did you use docker-compose run
or docker-compose up
?
According to docker documentation: "docker-compose run command does not create any of the ports specified in the service configuration."
Try to use docker-compose up command.
来源:https://stackoverflow.com/questions/56522164/how-to-get-the-port-numbers-for-a-service-docker-compose-file