Search code examples
dockershiny-server

Dockerfile cannot find executable script (no such file or directory)


I'm writting a Dockerfile in order to create an image for a web server (a shiny server more precisely). It works well, but it depends on a huge database folder (db/) that it is not distributed with the package, so I want to do all this preprocessing while creating the image, by running the corresponding script in the Dockerfile.

I expected this to be simple, but I'm struggling figuring out where my files are being located within the image.

This repo has the following structure:

Dockerfile
preprocessing_files
configuration_files
app/
    application_files
    db/
        processed_files

So that app/db/ does not exist, but is created and filled with files when preprocessing_files are run.

The Dockerfile is the following:

# 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 \
    libxml2-dev \
    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
RUN R -e "install.packages(c('shiny', 'flexdashboard','rmarkdown','tidyverse','plotly','DT','drc','gridExtra','fitdistrplus'), 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/
COPY /app/db /srv/shiny-server/app/

# Make the ShinyApp available at port 80
EXPOSE 80

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

This above file works well if preprocessing_files are run in advance, so app/application_files can successfully read app/db/processed_files. How could this script be run in the Dockerfile? To me the intuitive solution would be simply to write:

RUN bash -c "preprocessing.sh"

Before the ADD instruction, but then preprocessing_files are not found. If the above instruction is written below ADD and also WORKDIR app/, the same error happens. I cannot understand why.


Solution

  • You cannot execute code on the host machine from Dockerfile. RUN command executes inside the container being built. You can:

    • Copy preprocessing_files inside docker container and run preprocessing.sh inside the container (this would increase size of the container)
    • Create a makefile/build.sh script which launches preprocessing.sh before executing docker build