3

I am able to set up a Dockerfile with default ENV variables that I can then configure when running my docker container, e.g. in a Dockerfile I have the lines:

ENV USERNAME ropensci
ENV EMAIL ropensci@github.com
RUN git config --global user.name $USERNAME
RUN git config --global user.email $EMAIL

Great. When I launch an interactive session:

docker run -it --env USERNAME="Carl" --env EMAIL=cboettig@example.com myimage /bin/bash

I can then issue the command git config --list and see that git is configured to use the values I provided on the command line instead of the defaults.

However, my Dockerfile is also configured to run an RStudio server that I can then log into in the browser when running the image in Daemon mode:

docker run -d -p 8787:8787 --env USERNAME="Carl" --env EMAIL=cboettig@example.com cboettig/ropensci-docker

I go to localhost:8787 and log in to RStudio which all works as expected, start a new "Project" with git enabled, but then RStudio cannot find my git name & email. I can open the shell from the RStudio menu and run git config --list or echo $USERNAME and I just get a blank value. Why does this work for /bin/bash but not from RStudio and how do I fix it?

4

1 回答 1

2

您的 git 配置设置在 /.gitconfig 上。此配置文件适用于 root 用户。您需要为 rstudio 用户设置 git config,因为 rstudio 在 rstudio 用户上运行。下面的命令是一个临时解决方案。

docker run -it -p 8787:8787 --env USERNAME="Carl" --env EMAIL=cboettig@example.com cboettig/ropensci-docker bash -c "cp /.gitconfig /home/rstudio; /usr/bin/supervisord"

有用!

工作室

另一种解决方案是编写基于 cboettig/ropensci-docker 的 Dockerfile。下面是示例 Dockerfile。

FROM cboettig/ropensci-docker
RUN cp /.gitconfig /home/rstudio
CMD ["/usr/bin/supervisord"]
于 2014-08-16T04:50:02.553 回答