2 Customization scripts
The helper scripts at /pyrocket_scripts
in the image scripts to help do common tasks for extending the py-rocket-base image. Users can write their own Docker file code to do these tasks but the helper scripts provide standardized code for these tasks. The scripts are
install-conda-packages.sh
install-pip-packages.sh
install-r-packages.sh
install-apt-packages.sh
install-vscode-extensions.sh
install-desktop.sh
setup-start.sh
run-postbuild.sh
Note there are a few more scripts in /py-rocket-scripts
but those are tailored more to the base-image creation rather than extending the base image.
2.1 install-conda-packages.sh
The install-conda-packages.sh
script will install conda packages to the conda notebook environment, the user environment in the py-rocket-base image (same as for pangeo and repo2docker images).
Here is the code for your Docker file. You can name the conda package file to something other than environment.yml
. Make sure your file has name:
. The name is arbitrary. It is ignored but required for the script.
FROM ghcr.io/nmfs-opensci/py-rocket-base:latest
COPY environment.yml environment.yml RUN /pyrocket_scripts/install-conda-packages.sh environment.yml && rm environment.yml
environment.yml
name: required
channels:
- conda-forge
dependencies:
- cmocean
- numpy
Instead of a list of conda packages (typically called environment.yml), you can use a conda lock file instead.
Here is the code for your Docker file. You can name your conda lock file something other than conda-lock.yml
.
FROM ghcr.io/nmfs-opensci/py-rocket-base:latest
COPY conda-lock.yml conda-lock.yml RUN /pyrocket_scripts/install-conda-packages.sh conda-lock.yml && rm conda-lock.yml
2.2 install-pip-packages.sh
The install-pip-packages.sh
script will install packages using pip
. Here is the code for your Docker file. You can name your pip package file something other than requirements.txt
.
FROM ghcr.io/nmfs-opensci/py-rocket-base:latest
COPY requirements.txt requirements.txt RUN /pyrocket_scripts/install-pip-packages.sh requirements.txt && rm requirements.txt
requirements.txt
#a package harmony-py
2.3 install-r-packages.sh
The install-r-packages.sh
script will run the supplied R script which you can use to install R packages to the system library.
Here is the code for your Docker file. You can name the R script file to something other than install.R
. Make sure your file is an R script.
FROM ghcr.io/nmfs-opensci/py-rocket-base:latest
COPY install.R install.R RUN /pyrocket_scripts/install-r-packages.sh install.R && rm install.R
install.R example
# to match rocker/verse:4.4 used in py-rocker-base
# look up the date that the Rocker image was created and put that
repo <- "https://p3m.dev/cran/__linux__/jammy/2024-05-13"
list.of.packages <- c("ncdf4", "httr", "plyr", "lubridate") install.packages(list.of.packages, repos=repo)
2.3.1 Add R geospatial packages
Geospatial packages require some linux packages. To get this working in your Docker image add this to your Docker file:
Dockerfile
FROM ghcr.io/nmfs-opensci/py-rocket-base:latest
USER root
RUN PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin && \
/rocker_scripts/install_geospatial.sh USER ${NB_USER}
2.4 install-apt-packages.sh
The install-apt-packages.sh
script will install packages with apt-get
. Here is the code for your Docker file. You can name the apt file of packages names to something other than apt.txt
. Comments and newlines are allowed. Installation requires root.
FROM ghcr.io/nmfs-opensci/py-rocket-base:latest
USER root
COPY apt.txt apt.txt
RUN /pyrocket_scripts/install-apt-packages.sh apt.txt && rm apt.txt USER ${NB_USER}
apt.txt example
# Some useful stuff
tk-dev
# Add some more
cmocean
2.5 run-postbuild.sh
The run-postbuild.sh
script can be run as root or jovyan (${NB_USER}
). The script has some extra code to remove leftover files after installing Python extensions.
FROM ghcr.io/nmfs-opensci/py-rocket-base:latest
COPY postBuild postBuild RUN /pyrocket_scripts/run-postbuild.sh postBuild && rm postBuild
postBuild
#!/bin/bash -l
set -e
<bash commands>
2.6 setup-start.sh
The start
bash code is run when the image starts. py-rocker-base has a start script at ${REPO_DIR}/start
which loads the Desktop applications. If you change that start file (by copying your start file onto that location), then the Desktop apps will not be loaded properly. Instead, the setup-start.sh
will add your start file to a directory ${REPO_DIR}/childstarts
and will run all those scripts after ${REPO_DIR}/start
.
The setup-start.sh
script will move the file you provide into ${REPO_DIR}/childstarts
. As usual you can name your script something other than start
.
FROM ghcr.io/nmfs-opensci/py-rocket-base:latest
COPY start start RUN /pyrocket_scripts/setup-start.sh start && rm start
2.7 install-vscode-extensions.sh
The install-vscode-extensions.sh
script will add VSCode extensions to the conda notebook environment (in ${CONDA_PREFIX}/share/code-server/extensions
).
FROM ghcr.io/nmfs-opensci/py-rocket-base:latest
COPY vscode-extensions.txt vscode-extensions.txt
RUN /pyrocket_scripts/install-vscode-extensions.sh vscode-extensions.txt && \ rm vscode-extensions.txt
vscode-extensions.txt
gitlens
indent-rainbow
code-spell-checker prettier
2.8 Desktop applications
See the chapter on Desktop applications.