openanalytics / shinyproxy

ShinyProxy - Open Source Enterprise Deployment for Shiny and data science apps
https://www.shinyproxy.io
Apache License 2.0
525 stars 151 forks source link

Problems building off rocker-org images (instead of openanalytics/r-base) #28

Closed cpsievert closed 7 years ago

cpsievert commented 7 years ago

Using this application.yml file and the nginx config below I'm able to see the landing page at http://165.227.184.97/, but it can't find the appropriate web assets (e.g., bootstrap).

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

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name localhost;

    location / {

        proxy_pass                            http://127.0.0.1:8080/;
            proxy_http_version                    1.1;
            proxy_set_header Upgrade              $http_upgrade;
            proxy_set_header Connection           "upgrade";
            proxy_read_timeout                    600s;
            proxy_redirect                        off;
            proxy_set_header Host                 $http_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-Protocol $scheme;

        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

}

Not sure where to look to investigate (I'm not very familiar with Java/Spring), so any pointers would be much appreciated!

cpsievert commented 7 years ago

Ah, it appears I may not have the proxy configured correctly...this works ok http://165.227.184.97:8080/

cpsievert commented 7 years ago

A more important/relevant issue now is this container not found: http://165.227.184.97:8080/app/zikar

screen shot 2017-11-03 at 7 42 15 pm

My docker service is running, but perhaps that is configured incorrectly

$ sudo service docker status
docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2017-11-02 21:30:23 UTC; 1 day 2h ago Docs: https://docs.docker.com Main PID: 18203 (dockerd) Tasks: 22 Memory: 740.8M CPU: 3min 58.110s CGroup: /system.slice/docker.service ├─18203 /usr/bin/dockerd -H fd:// -D -H tcp://127.0.0.1:2375 └─18211 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc --debug Nov 03 23:56:21 shinyproxy dockerd[18203]: time="2017-11-03T23:56:21.134548912Z" level=debug msg="Revoking external connectivity on endpoint reverent_babbage (10064b7f64d2081604762c6c811dcb42a60f698ea87025a96541091850fa3752)" Nov 03 23:56:21 shinyproxy dockerd[18203]: time="2017-11-03T23:56:21.137346286Z" level=debug msg="/sbin/iptables, [--wait -t nat -C DOCKER -p tcp -d 0/0 --dport 20000 -j DNAT --to-destination 172.17.0.2:3838 ! -i docker0]" Nov 03 23:56:21 shinyproxy dockerd[18203]: time="2017-11-03T23:56:21.143200088Z" level=debug msg="/sbin/iptables, [--wait -t nat -D DOCKER -p tcp -d 0/0 --dport 20000 -j DNAT --to-destination 172.17.0.2:3838 ! -i docker0]" Nov 03 23:56:21 shinyproxy dockerd[18203]: time="2017-11-03T23:56:21.147734769Z" level=debug msg="/sbin/iptables, [--wait -t filter -C DOCKER ! -i docker0 -o docker0 -p tcp -d 172.17.0.2 --dport 3838 -j ACCEPT]" Nov 03 23:56:21 shinyproxy dockerd[18203]: time="2017-11-03T23:56:21.152275576Z" level=debug msg="/sbin/iptables, [--wait -t filter -D DOCKER ! -i docker0 -o docker0 -p tcp -d 172.17.0.2 --dport 3838 -j ACCEPT]" Nov 03 23:56:21 shinyproxy dockerd[18203]: time="2017-11-03T23:56:21.157009713Z" level=debug msg="/sbin/iptables, [--wait -t nat -C POSTROUTING -p tcp -s 172.17.0.2 -d 172.17.0.2 --dport 3838 -j MASQUERADE]" Nov 03 23:56:21 shinyproxy dockerd[18203]: time="2017-11-03T23:56:21.161614234Z" level=debug msg="/sbin/iptables, [--wait -t nat -D POSTROUTING -p tcp -s 172.17.0.2 -d 172.17.0.2 --dport 3838 -j MASQUERADE]" Nov 03 23:56:21 shinyproxy dockerd[18203]: time="2017-11-03T23:56:21.166723221Z" level=debug msg="DeleteConntrackEntries purged ipv4:0, ipv6:0" Nov 03 23:56:21 shinyproxy dockerd[18203]: time="2017-11-03T23:56:21.248686165Z" level=debug msg="Releasing addresses for endpoint reverent_babbage's interface on network bridge" Nov 03 23:56:21 shinyproxy dockerd[18203]: time="2017-11-03T23:56:21.248739605Z" level=debug msg="ReleaseAddress(LocalDefault/172.17.0.0/16, 172.17.0.2)"

Or do I need to manually run containers in a daemon mode? I thought shinyproxy handled that part?

tverbeke commented 7 years ago

Hi @cpsievert To make sure all is configured correctly, it may be useful to work through the getting started guide at https://www.shinyproxy.io/getting-started/ You are right that ShinyProxy takes care of launching and shutting down containers (so there is no need to manually run any containers). Did you docker pull the relevant images onto the machine?

Regarding the proxy, there is an example nginx config given at https://www.shinyproxy.io/security/ which can be used as a starting point (e.g. no root is being specified etc.). Feel free to ask other support questions on our community support site at https://support.openanalytics.eu/

cpsievert commented 7 years ago

Did you docker pull the relevant images onto the machine?

Yep:

sudo docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
cpsievert/apps                  shiny-testing       8f8b33cc0204        28 hours ago        784MB
cpsievert/apps                  shiny-zikar         27f0aa12ba04        29 hours ago        1GB
alpine                          latest              37eec16f1872        10 days ago         3.97MB
ubuntu                          latest              747cb2d60bbe        3 weeks ago         122MB
ubuntu                          xenial              747cb2d60bbe        3 weeks ago         122MB
ubuntu                          trusty              dea1945146b9        7 weeks ago         188MB
hello-world                     latest              05a3bd381fc2        7 weeks ago         1.84kB
openanalytics/shinyproxy-demo   latest              d5c1f575e01e        7 months ago        828MB

Feel free to ask other support questions on our community support site at https://support.openanalytics.eu/

Good to know, thanks!

tverbeke commented 7 years ago

@cpsievert: OK. Were you able to launch the Docker image manually (outside of ShinyProxy) and access the application ? If not, something may be wrong with the app or the way the launch command was issued. Did you actually copy the shiny app files (server.R, ui.R etc.) into a specific directory of the Docker image? You do not specify a specific directory in your runApp commands, so by default that will be /root.

Also (irrelevant for the issue, but maybe useful) I noticed you specify port and host for every app. In https://github.com/openanalytics/shinyproxy-template you will see how to use Rprofile.site to do this container-side.

Let us know if you find out what the cause was. It would be good to add some content on this error message on our troubleshooting page https://www.shinyproxy.io/troubleshooting/. There is already https://www.shinyproxy.io/troubleshooting/#failed-to-start-container but the detailed error message there seems different from yours (and typically has to do with inappropriate firewall rules).

cpsievert commented 7 years ago

Were you able to launch the Docker image manually (outside of ShinyProxy) and access the application ?

Yep, for example, running https://github.com/cpsievert/apps/blob/17c8e5/shiny/template/Dockerfile#L10

$ docker run -p 3838:3838 cpsievert/apps:shiny-template
R version 3.4.2 (2017-09-28) -- "Short Summer"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> shiny::runApp(port=3838, host="0.0.0.0")
Loading required package: shiny

Listening on http://0.0.0.0:3838
$ curl http://localhost:3838
<!DOCTYPE html>
<html>
<head>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <script type="application/shiny-singletons"></script>
  <script type="application/html-dependencies">json2[2014.02.04];jquery[1.12.4];shiny[1.0.5];bootstrap[3.3.7]</script>
<script src="shared/json2-min.js"></script>
<script src="shared/jquery.min.js"></script>
<link href="shared/shiny.css" rel="stylesheet" />
<script src="shared/shiny.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="shared/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<script src="shared/bootstrap/js/bootstrap.min.js"></script>
<script src="shared/bootstrap/shim/html5shiv.min.js"></script>
<script src="shared/bootstrap/shim/respond.min.js"></script>

</head>

<body>
  <div class="container-fluid">
    <div id="p" class="shiny-plot-output" style="width: 100% ; height: 400px"></div>
  </div>
</body>

</html>
cpsievert commented 7 years ago

Did you actually copy the shiny app files (server.R, ui.R etc.) into a specific directory of the Docker image?

Yep, I'm currently just copying the app files to the working directory (at build time).

You do not specify a specific directory in your runApp commands, so by default that will be /root.

The directory for runApp() actually defaults to getwd(), so I don't think that is universally true. Nevertheless, I can try placing app files under /root and manually specifying the directory in runApp() to see that fixes it

tverbeke commented 7 years ago

Since the default user under which Docker runs the process will be root, getwd() will give /root.

cpsievert commented 7 years ago

Ohh, perhaps some of the problem(s) are due to the fact that I'm building off of rocker-org/r-ver, not your custom r-base image?

It'd be great if there were some rough guidelines for working off of rocker images (so we can easily take advantage of different R versions and package bundles) -- for example, should this be sufficient to run the container via shinyproxy? Or do we need some of these system dependencies? etc

cpsievert commented 7 years ago

One important difference between these images is the location of R.home() (rocker: /usr/local/lib/R, openanalytics: /usr/lib/R). I suppose that could also be why I'm having difficulty specifying the host/port through /usr/lib/R/Rprofile.site

tverbeke commented 7 years ago

Hi @cpsievert I think you are onto something (vaguely recall a similar issue) and I agree it would be good to provide guidelines on using Rocker images with ShinyProxy - thanks for your updates!

mnazarov commented 7 years ago

Hi @cpsievert, I don't think your issue is related to the docker image. There is not much difference between rocker and openanalytics images, and the lines you highlighted are optional. As a minimal example I was able to run an app from an image built from the following Dockerfile:

FROM rocker/r-ver:latest
RUN apt-get update && apt-get install -y \
    sudo \
    libcurl4-gnutls-dev \
    libcairo2-dev \
    libxt-dev \
    libssl-dev \
    libssh2-1-dev
RUN R -e "install.packages('shiny')"
EXPOSE 3838
CMD ["R", "-e shiny::runExample('01_hello',port=3838,host='0.0.0.0')"]

A possible reason is the extra spaces in the docker-cmd fields: Try to change docker-cmd: R -e 'shiny::runApp(port=3838, host="0.0.0.0")' into docker-cmd: ["R", "-e shiny::runApp(port=3838,host='0.0.0.0')"] in your application.yml file.

If this doesn't help, please try the default application.yml with the shinyproxy-demo image and see if it works.

cpsievert commented 7 years ago

Thanks. It seems ["R", "-e shiny::runApp(port=3838,host='0.0.0.0')"] doesn't work either, but this does: ["R", "-e", "shiny::runApp(port=3838, host='0.0.0.0')"]

(it'd be great if the docs reflected this more 'correct' way (the other way doesn't seem to support R code that contains strings).

cpsievert commented 7 years ago

Closing as I think the previous comment was the root of my issues, thanks for all the help!

tverbeke commented 7 years ago

Documentation on https://www.shinyproxy.io/ has now been updated to consistently use the equivalent of ["R", "-e", "shiny::runApp(port=3838, host='0.0.0.0')"] - the example configuration inside the ShinyProxy repository will also be updated with the next release.