OHIF / Viewers

OHIF zero-footprint DICOM viewer and oncology specific Lesion Tracker, plus shared extension packages
https://docs.ohif.org/
MIT License
3.32k stars 3.35k forks source link

Not able to connect to localhost orthanc when running ohif viewer and orthanc as separate docker containers #2210

Closed rvadhith closed 1 year ago

rvadhith commented 3 years ago

I am trying to connect ohif viewer and orthanc by running them as separate containers. But when I access ohif viewer in port http://localhost:8002/, I am getting 502 bad gateway error

I am running ohif viewer by using the docker image from https://hub.docker.com/r/ohif/viewer. I am running orthanc using docker with the following command (docker run -p 4242:4242 -p 8042:8042 --rm jodogne/orthanc-plugins)

If I go to http://localhost:8042/app/explorer.html, I would be able to access orthanc

Orthanc_from_docker

I am starting the ohif viewer with the following command:

docker run -d -v /home/adhithya/AIkenist/app-config.js:/usr/share/nginx/html/app-config.js -v /home/adhithya/AIkenist/nginx.conf:/etc/nginx/nginx.conf -p 8002:80 ohif/viewer:latest

I have replaced the app-config.js file in /usr/share/nginx/html/ using the following app-config.js file

window.config = {
  routerBasename: '/',
  servers: {
    dicomWeb: [
      {
        name: 'Orthanc',
        wadoUriRoot: 'http://localhost:8042/wado',
        qidoRoot: 'http://localhost:8042/dicom-web',
        wadoRoot: 'http://localhost:8042/dicom-web',
        qidoSupportsIncludeField: false,
        imageRendering: 'wadors',
        thumbnailRendering: 'wadors',
      },
    ],
  },
};

I have replaced the nginx.conf file in /etc/nginx/nginx.conf using the following nginx.conf file

worker_processes 1;

events { worker_connections 1024; }

http {
    upstream orthanc-server {
        server localhost:8042;
    }

    server {
        listen [::]:80 default_server;
        listen 80;

        # CORS Magic
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow_Credentials' 'true';
        add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
        add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';

        location / {

            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow_Credentials' 'true';
                add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
                add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain charset=UTF-8';
                add_header 'Content-Length' 0;
                return 204;
            }

            proxy_pass         http://localhost:8042;
            proxy_redirect     off;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;

            # CORS Magic
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow_Credentials' 'true';
            add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
        }
    }
}

When I go to port http://localhost:8002/ to access ohif viewer I am getting the following error

ohif_viewer_error

I got the following log messages in the ohif viewer docker container

Starting Nginx to serve the OHIF Viewer... 2020/12/16 02:44:01 [error] 6#6: 2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: , request: "GET /index.es.js.map HTTP/1.1", upstream: "http://127.0.0.1:8042/index.es.js.map", host: "localhost:8002" 2020/12/16 02:44:01 [crit] 6#6: 2 connect() to [::1]:8042 failed (99: Address not available) while connecting to upstream, client: 172.17.0.1, server: , request: "GET /index.es.js.map HTTP/1.1", upstream: "http://[::1]:8042/index.es.js.map", host: "localhost:8002" 172.17.0.1 - - [16/Dec/2020:02:44:01 +0000] "GET /index.es.js.map HTTP/1.1" 502 559 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"

I am doing something wrong with the nginx.conf file. I am not setting the server in the right format in upstream orthanc-server. @dannyrb Could you please let me know what are the changes I need to make. Could you also let me know if I have to alter the the orthanc configuration and if so how should I make the required alterations

olivert1969 commented 3 years ago

Hi @rvadhith since you're using multiple containers, you may want to use Docker Compose https://docs.docker.com/compose/. Here is a working docker-compose.yml file for Orthanc and OHIF. Set the individual config files for nginx.conf, orthanc.json and viewer.js to your needs.

version: '3.6' services:

orthanc: image: osimis/orthanc container_name: orthanc depends_on:

networks: frontend: backend:

volumes: certbot-etc: certbot-var: web-root: driver: local driver_opts: type: none device: [host filesystem location] o: bind dhparam: driver: local driver_opts: type: none device: [host filesystem location] o: bind

sedghi commented 1 year ago

Please review the latest code in the master branch. I am confident that this issue has been resolved. If it persists, kindly reopen the issue with updated details.

Try viewer-dev.ohif.org instead of viewer.ohif.org Our viewer.ohif.org is deployed from release branch while viewer-dev.ohif.org is our master branch Read more about branch explanations here https://docs.ohif.org/development/getting-started#developing