rocker-versioned icon indicating copy to clipboard operation
rocker-versioned copied to clipboard

Change default RStudio start-up working directory?

Open 2533245542 opened this issue 5 years ago • 7 comments

Hello,

I used RStudio a lot but I am pretty new to rocker and Docker.

Currently, when starting the RStudio in Docker, it defaults to point to /home/rstudio as working directory.

I am wondering if there is a way to set a customized working directory such that when starting up, RStudio goes to the customized working directory directly?

I tried adding this to the docker file to change the default working directory of RStudio but it didn't work.

RUN echo "setwd(\"~/../home/rstudio/workspace/\")" > ~/.Rprofile #set up working diretory

2533245542 avatar Apr 06 '21 23:04 2533245542

docker ....all other arguments... -w /foo container will start in /foo so a common paradigm is -v $PWD:/mnt -w /mnt which first brings the current directory "inside" as /mnt via -v and then starts there via -w.

eddelbuettel avatar Apr 06 '21 23:04 eddelbuettel

docker ....all other arguments... -w /foo container will start in /foo so a common paradigm is -v $PWD:/mnt -w /mnt which first brings the current directory "inside" as /mnt via -v and then starts there via -w.

Thanks for the help! I used docker-compose to create the container so I cannot directly use your answer. Do you have any idea to do that in a docker network? Here is the part RStudio container in my docker-compose.yml file and app is the container name of the RStudio.

    app:
        build:
            context: ./src/app
        environment:
            PASSWORD: "${RSTUDIO_PASSWORD}"
        volumes:
            - ./src/app/workspace:/home/rstudio/workspace
        ports:
            - "8787:8787"
        depends_on:
            - api
        networks:
            default:
                aliases:
                    - app

2533245542 avatar Apr 06 '21 23:04 2533245542

Maybe this can help: https://stackoverflow.com/questions/40248908/context-or-workdir-for-docker-compose

eddelbuettel avatar Apr 07 '21 12:04 eddelbuettel

Problem solved. This line of code was added to the docker file. RUN echo "setwd(\"/home/rstudio/workspace/\")" > ~/../home/rstudio/.Rprofile #set up working diretory

2533245542 avatar Apr 08 '21 18:04 2533245542

this works but how can we set the working directory Files pane on the right side? It defaults to the /home/user directory where there is an rstudio folder with kitematic subfolder in it

sktrinh12 avatar Oct 07 '21 00:10 sktrinh12

These days we are using this in another setting (and I am a bystander here, someone else worked this out):

USER rstudio
ENV EDITOR_FOCUS_DIR "/home/rstudio/workspace"
RUN mkdir -p "$EDITOR_FOCUS_DIR"

There may be additional documentation in some places...

eddelbuettel avatar Oct 07 '21 01:10 eddelbuettel

These days we are using this in another setting (and I am a bystander here, someone else worked this out):

USER rstudio
ENV EDITOR_FOCUS_DIR "/home/rstudio/workspace"
RUN mkdir -p "$EDITOR_FOCUS_DIR"

There may be additional documentation in some places...

Tried this, no error when building the image but had an error when running the container: s6-mkdir: warning: unable to mkdir /var/run/s6: Permission denied when running the container.

Dockerfile:

FROM rocker/verse:3.6.1
USER rstudio
ENV EDITOR_FOCUS_DIR "/home/rstudio/workspace"
RUN mkdir -p "$EDITOR_FOCUS_DIR"

Build command: docker build -t rstudio_test . Run command: docker run -d -p 8787:8787 -e PASSWORD=yourpasswordhere rstudio_test

The good news is that the error disappeared when commenting USER rstudio, but the bad news is that the file pane is still defaulted to be /home/rstudio rather than /home/rstudio/workspace

2533245542 avatar Oct 07 '21 01:10 2533245542