I'm not sure why you are seeing different behaviour with you database connections and images. But I can tell you what you are asking the CMD
statement to do in each case.
CMD ["/usr/bin/shiny-server.sh"]
This will start shiny-server and is the preferred way of running shiny apps for production. The biggest benefit is that you can have multiple R sessions, managed by shiny-server. For example if you have multiple users and need the application to scale. You can adjust the resources allocated to your docker container, and shiny-server will be able to make use of the additional resources.
You may not be able to access your database because usually shiny-server
runs as the user shiny
, and you database settings may be expecting a different user. You can can change the (linux) user that is used to run your app in the shiny-server configuration files.
CMD ["Rscript", "app.R"]
You running your app as you would any other R script from the console. Thanks to the "single file app" structure this will run, and only in this case. Should you have an app with a server.R
and ui.R
file than you would not be able to call it like this. Having separate server.R
and ui.R
files is common in larger shiny apps, so this might not be the best way to go about it.
Also I'm not sure if this will set the current working directory correctly. And this is probably why it does not find your image (the process is unaware of your www folder).
CMD ["R", "-e", "shiny::runApp()"]
This works, and sets the working directory of your app, but you are limited to only one R Process. Maybe that is enough for your use case, but as soon as you have more users you will likely want to move this to shiny server. Joe Cheng once explained the diferences in the shiny chat.