dockr
is a small toolkit to build a lightweight Docker r-base
container image for your R package, in which the package itself is
available. The Docker image seeks to mirror your R session as close as
possible with respect to R specific dependencies. Both dependencies on
CRAN R packages as well as local non-CRAN R packages will be included in
the Docker container image.
Install the development version of dockr
with:
remotes::install_github("smaakage85/dockr")
Or install the version released on CRAN:
install.packages("dockr")
In order to create the files, that will constitute the Docker image,
simply invoke the prepare_docker_image()
function and point to the
folder with your package.
The workflow of prepare_docker_image()
is summarized below:
- Build and install the package on your system
- Identify R package dependencies of the package
- Detect the version numbers of the loaded and installed versions of these packages on your system
- Link the individual packages to the right repositories (either CRAN or local repos)
- Write Dockerfile and create all other files needed to build the Docker r-base image
Now, I will let dockr
do its magic and create the files for a Docker
r-base container image, in which dockr
is installed together with all
of the R package dependencies, dockr
needs to run.
Beware that the files for the Docker image are created as side-effects of the function call (under the ‘dir_image’ directory). Also the package is installed as a side effect (in the ‘dir_install’ directory).
library(dockr)
image_dockr <- prepare_docker_image(".", dir_image = tempdir(),
dir_install = "temp")
#> v Creating folder for files for Docker image: C:\Users\Lars\AppData\Local\Temp\Rtmpw7ckvG/dockr_0.8.2
#> v Creating folder for source packages: C:\Users\Lars\AppData\Local\Temp\Rtmpw7ckvG/dockr_0.8.2/source_packages
#> v Creating empty Dockerfile: C:\Users\Lars\AppData\Local\Temp\Rtmpw7ckvG/dockr_0.8.2/Dockerfile
#> --- Building, installing and loading package...
#> Writing NAMESPACE
#> Writing NAMESPACE
#> --- Writing Dockerfile...
#> v Preparing FROM statement
#> v Identifying and mirroring R package dependencies
#> v Matching dependencies with CRAN packages
#> v Preparing install statements for specific versions of CRAN packages
#> v Preparing install statement for the package itself
#> v Writing lines to Dockerfile
#> v Closing connection to Dockerfile
#> - in R :
#> => to inspect Dockerfile run:
#> dockr::print_file("C:\Users\Lars\AppData\Local\Temp\Rtmpw7ckvG/dockr_0.8.2/Dockerfile")
#> => to edit Dockerfile run:
#> dockr::write_lines_to_file([lines], "C:\Users\Lars\AppData\Local\Temp\Rtmpw7ckvG/dockr_0.8.2/Dockerfile")
#> - in Shell :
#> => to build Docker image run:
#> cd C:\Users\Lars\AppData\Local\Temp\Rtmpw7ckvG\dockr_0.8.2
#> docker build -t dockr_0.8.2 .
#> Please note that Docker must be installed in order for you to build image.
Great, all necessary files for the Docker image have been created, and you can build the Docker image right away by following the instructions. It is as easy as that! Yeah!
dockr
does not deal with non-R dependencies at this point. In case
that, for instance, your package has any Linux specific dependencies,
you will have to install them yourself in the Docker container image.
For that purpose you can edit the Dockerfile further with the
‘write_lines_to_file’ function.
I hope, that you will find dockr
useful.
Please direct any questions and feedbacks to me!
If you want to contribute, open a PR.
If you encounter a bug or want to suggest an enhancement, please open an issue.
Best, smaakagen