Skip to content
This repository has been archived by the owner on Mar 2, 2022. It is now read-only.

Change default RStudio start-up working directory? #255

Open
2533245542 opened this issue Apr 6, 2021 · 7 comments
Open

Change default RStudio start-up working directory? #255

2533245542 opened this issue Apr 6, 2021 · 7 comments

Comments

@2533245542
Copy link

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

@eddelbuettel
Copy link
Member

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.

@2533245542
Copy link
Author

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

@eddelbuettel
Copy link
Member

@2533245542
Copy link
Author

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

@sktrinh12
Copy link

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

@eddelbuettel
Copy link
Member

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...

@2533245542
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants