4

I'm trying to put my shiny app in docker container. My shiny app works totally fine on my local computer. But after dockerize my shiny app, I always have error message on my localhost like The application failed to start. The application exited during initialization..

I have no idea why that happens. I'm new to docker. How can I find the error logs when I run the docker image? I need the log to know what goes wrong.

Here is my dockfile:

# Install R version 3.6
FROM r-base:3.6.0

# Install Ubuntu packages
RUN apt-get update && apt-get install -y \
    sudo \
    gdebi-core \
    pandoc \
    pandoc-citeproc \
    libcurl4-gnutls-dev \
    libcairo2-dev/unstable \
    libxt-dev \
    libssl-dev

# Download and install ShinyServer (latest version)
RUN wget --no-verbose https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/VERSION -O "version.txt" && \
    VERSION=$(cat version.txt)  && \
    wget --no-verbose "https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && \
    gdebi -n ss-latest.deb && \
    rm -f version.txt ss-latest.deb

# Install R packages that are required
# TODO: add further package if you need!
RUN R -e "install.packages(c( 'tidyverse', 'ggplot2','shiny','shinydashboard', 'DT', 'plotly', 'RColorBrewer'), repos='http://cran.rstudio.com/')"
# Copy configuration files into the Docker image
COPY shiny-server.conf  /etc/shiny-server/shiny-server.conf
COPY /app /srv/shiny-server/

# Make the ShinyApp available at port 80
EXPOSE 80

# Copy further configuration files into the Docker image
COPY shiny-server.sh /usr/bin/shiny-server.sh

CMD ["/usr/bin/shiny-server.sh"]

I built image and ran like below:

docker build -t myshinyapp .
docker run -p 80:80 myshinyapp
zesla
  • 11,155
  • 16
  • 82
  • 147
  • Have you noticed any error while building image? – minhazur Jun 29 '19 at 02:11
  • I did not noticed any error. everything looks fine. – zesla Jun 29 '19 at 02:12
  • Can you please, rebuild the image removing `--no-verbose` after wget and see the output? – minhazur Jun 29 '19 at 02:15
  • I will give it a try. But the thing is I used the same dockfile for a very simple app and it works.... so it should be something about my app. But my app is totally fine when I run it on local. so I'm confused, spend hours to figure it out but failed.... – zesla Jun 29 '19 at 02:19
  • You might be having another service running (maybe your own app or, for example, an nginx or apache service) using/reserving that port 80 of your host, preventing docker to start your container with that same port. Take a look at [my answer here](https://stackoverflow.com/a/56814736/11693924) for more details. – Fisharp Jun 29 '19 at 02:59

1 Answers1

8

Usually the logs for any (live or dead) container can be found by just using:

docker logs full-container-name

or

docker logs CONTAINERID

(replacing the actual ID of your container)

As first said, this usually works as well even for stopped (not still removed) containers, which you can list with:

docker container ls -a

or just

docker ps -a

However, sometimes you won't even have a log, since the container was never created at all (which I think, by experience, fits more to your case)

And it can be happening simply because the docker engine is unable to allocate all of the resources that your service definition is requiring to have available.

The application failed to start. The application exited during initialization

is usually reflect of your docker engine being unable to get the required resources.

And the most common case for that, is just as simple as your host ports:

If you have another service (being dockerized or not) using (for example) that port that you want to use for your service (in your case, port 80) then Docker would just be unable to start your container.

So... in short... the easiest fix for that situation (and your first try whenever you face this kind of issues) is just to bind any other port from your host (say: 8080), to that 80 port that your service will be listening to internally (inside your container):

docker run -p 8080:80 myshinyapp

The same principle applies to unallocatable volumes (e.g.: trying to bind a volume as read-only that doesn't actually exist in the host)


As an aside comment/trick:

Since you're not setting a name for your container, you will need to use the container id instead when looking for its logs.

But instead of typing (or copy-pasting) the full container id (usually something like: 1283c66babea or even larger) you can just type in a few first digits instead, and it will still work as expected:

docker logs 1283c6 or docker logs 1283 or even docker logs 128

(of course... as long as you don't have any other 128***** container)

Fisharp
  • 554
  • 3
  • 10