So committing is not a super good way to capture changes. Because you have to manually go through all the steps again. https://docs.docker.com/engine/reference/commandline/commit/
You'll be much better off in the long run if you get in the habit of building up your image from a dockerfile. If your first call in your dockerfile is, for example:
FROM rocker/rstudio-stable:devel
then your image will be built with the latest rstudio stable devel version. In order to update you just rebuild the image and the latest version is pulled. Super simple!
so the next command in your dockerfile might be to copy over a script that loads all your packages. I call mine
add_r_kernel.sh because I load packages an install a JupyterLab kernel (which you probably don't need). So this copies over files and then changes permissions on the script and runs it:
ADD add_r_kernel.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/add_r_kernel.sh && \
/usr/local/bin/add_r_kernel.sh
The contents of my add_r_kernel.sh are as follows:
#!/bin/Rscript
install.packages(
c('pkgbuild',
'crayon',
'pbdZMQ',
'httr',
'withr',
'usethis',
'devtools',
'rlang',
'uuid',
'digest',
'callr'),
repos='http://cran.us.r-project.org' )
install.packages(
c(
'tidyverse',
'devtools',
'formatR',
'remotes',
'selectr',
'caTools',
'stringi'),
repos='http://cran.us.r-project.org' )
install.packages(
c(
'curl',
'openssl',
'git2r',
'gh',
'odbc'),
repos='http://cran.us.r-project.org' )
devtools::install_github('IRkernel/IRkernel')
IRkernel::installspec(user = FALSE)
You won't need most of that junk because most of it is already installed on your image from rocker. I do it in chunks for testing and making it easy to comment out bits as needed. It could all be one big command.
I hope this helps!