Home > other >  Getting Docker run error File does not exist or is non-readable. getwd()=='/'?
Getting Docker run error File does not exist or is non-readable. getwd()=='/'?

Time:05-21

I got error related to reading file when I run docker run ..., while the shiny app works well in Rstudio.

All data (Input tables), shiny app .R file and Docker file are in the same folder.

First line of shiny app that I got error in docker run:

gene<-data.frame(data.table::fread('PCR_Gene_CP.GZ.csv'))

and Docker file is:

# get shiny packages image
FROM rocker/shiny:latest

#system libraries of general use
## install debian packages
RUN apt-get update -qq && apt-get -y --no-install-recommends install libxml2-dev libcairo2-dev 
libsqlite3-dev libmariadbd-dev libpq-dev libssh2-1-dev unixodbc-dev libcurl4-openssl-dev libssl-dev

## update system libraries
RUN apt-get update && apt-get upgrade -y && apt-get clean

# install R packages required 
# (change it dependeing on the packages you need)
RUN R -e "install.packages(pkgs=c('shiny','ggplot2','data.table','DT','dplyr','tidyr','tibble','VennDiagram'), repos='http://cran.rstudio.com/')"

COPY /app.R /app.R

# expose port
EXPOSE 3838

# run app on container start
CMD ["R", "-e", "shiny::runApp('/app.R', host = '0.0.0.0', port = 3838)"]

Running Docker build,run and logs:

docker build -t enhancer .
docker run -p 8081:3838 --name enhancer -d enhancer

docker logs -t enhancer

enter image description here

CodePudding user response:

Most of your Dockerfile is doing package installations (either from Linux or from what I assume is a repository of R modules). The only thing you copy from your own code directory is this file:

COPY /app.R /app.R

Since the csv file is not copied into the image, it does not exist there and your application therefore cannot open it.

If you only need that one data file, you can solve this by changing your copy line:

COPY app.R PCR_Gene_CP.GZ.csv /

Which would copy both the R file and the cvs file to / in the image.

If other data files (or anything else) must be in the image, you can add more files there. You can also copy everything:

COPY . /

Or you can use various wildcards to match multiple files. More documentation can be found here:

https://docs.docker.com/engine/reference/builder/#copy

  • Related