I want to import a rocker docker image into WSL and use it as a WSL distribution (I do this already with other Docker images based on Ubuntu) and use the pre-installed rstudio-server
that comes with it.
The command for importing a docker image tarball as a WSL distribution is:
wsl --import <DistributionName> <InstallLocation> <Full path to .tar FileName>
. This works just fine
However, on startup, certain services do not work because "/init", the CMD used for the docker image that gets rstudio-server running, is stuck in some limbo state when imported into WSL, or otherwise does not work (it's hard to tell what's going on).
My question: How would one use rocker/geospatial:4.4.2
or rocker/rstudio:4.4.2
as a WSL distribution and actually use rstudio-server
, which is installed as a service?
I currently maintain Dockerfiles that specify Ubuntu-based images for importing into WSL as distributions. This helps my Data Scientist users get into a unix-based operating system even though we only have access to Windows at work.
When I use basic Ubuntu docker images, such as ubuntu:22.04
, I can build the image, export to a .tar.gz
, then call wsl --import
to import the image into WSL 2 as distribution. This works well! However, I'd really love to use a rocker base image with rstudio, and this does not work, as it seems to rely on a "/init" directive that only runs when docker runs. When run as a WSL distribution, I cannot seem to get this "/init" binary (script?) to run (there is no output nor error when I try), nor can I start rstudio-server the manual way, with sudo rstudio-server start
You can see the error message I get here, in a WSL distribution based on rocker/geospatial:4.4.2
Uninstalling and Reinstalling rstudio-server does not work.
It seems that rocker wants to run "/init" as the overriding command and is never meant to be exited nor run in the background.
Take a look at the Dockerfile for rocker/geospatial:4.4.2
:
ENV R_VERSION="4.4.2"
ENV R_HOME="/usr/local/lib/R"
ENV TZ="Etc/UTC"
COPY scripts/install_R_source.sh /rocker_scripts/install_R_source.sh
RUN /rocker_scripts/install_R_source.sh
ENV CRAN="https://p3m.dev/cran/__linux__/noble/latest"
ENV LANG=en_US.UTF-8
COPY scripts/bin/ /rocker_scripts/bin/
COPY scripts/setup_R.sh /rocker_scripts/setup_R.sh
RUN <<EOF
if grep -q "1000" /etc/passwd; then
userdel --remove "$(id -un 1000)";
fi
/rocker_scripts/setup_R.sh
EOF
COPY scripts/install_tidyverse.sh /rocker_scripts/install_tidyverse.sh
RUN /rocker_scripts/install_tidyverse.sh
ENV S6_VERSION="v2.1.0.2"
ENV RSTUDIO_VERSION="2024.12.1+563"
ENV DEFAULT_USER="rstudio"
COPY scripts/install_rstudio.sh /rocker_scripts/install_rstudio.sh
COPY scripts/install_s6init.sh /rocker_scripts/install_s6init.sh
COPY scripts/default_user.sh /rocker_scripts/default_user.sh
COPY scripts/init_set_env.sh /rocker_scripts/init_set_env.sh
COPY scripts/init_userconf.sh /rocker_scripts/init_userconf.sh
COPY scripts/pam-helper.sh /rocker_scripts/pam-helper.sh
RUN /rocker_scripts/install_rstudio.sh
EXPOSE 8787
CMD ["/init"] # jkix's note: this seems imperative, somehow
COPY scripts/install_pandoc.sh /rocker_scripts/install_pandoc.sh
RUN /rocker_scripts/install_pandoc.sh
COPY scripts/install_quarto.sh /rocker_scripts/install_quarto.sh
RUN /rocker_scripts/install_quarto.sh
ENV CTAN_REPO="https://mirror.ctan.org/systems/texlive/tlnet"
ENV PATH="$PATH:/usr/local/texlive/bin/linux"
COPY scripts/install_verse.sh /rocker_scripts/install_verse.sh
COPY scripts/install_texlive.sh /rocker_scripts/install_texlive.sh
RUN /rocker_scripts/install_verse.sh
COPY scripts/install_geospatial.sh /rocker_scripts/install_geospatial.sh
RUN /rocker_scripts/install_geospatial.sh
COPY scripts /rocker_scripts
My Dockerfile essentially just uses the above as abase image (FROM: rocker/geospatial:4.4.2
) with some extra apt-get
commands and r2u
. Nothing too fancy from a docker standpoint. Just a whole bunch of RUN
steps.
I've tried a few other things in my Dockerfile, which also don't work:
To be clear: the problem I'm trying to solve is "why does rstudio-server not launch from the rocker-based WSL distribution?".
My question: do I have any recourse if I want to use this image, or is it better to stick with Ubuntu:22.04? Is there some way I can use all the goodies that come with the Rocker geospatial image without relying on the /init CMD, or would I be better off recreating a similar environment just using a chain of sudo apt-get
commands?
Also relevant, perhaps, is the way that Rstudio is installed to begin with - I am struggling to understand some of this, so any help would be appreciated (or even just some tough love 'hey just stick to a simpler system :)') https://github.com/rocker-org/rocker-versioned2/blob/master/scripts/install_rstudio.sh
Interestingly, the answer had nothing to do with what I thought it did.
rocker/geospatial had nothing to do with this at all - instead, I had found an error in my /etc/fstab
file (the file that handles drive mounts) that was hanging and preventing any service from initializing.
Generally, it seems that services may fail to start if other services which the system relies on have errors. This may be entirely obscured - so check your services and startup scripts, including /etc/fstab
errors, to see if anything is blocking the initialization of other services.
Specifically, though, what was happening was that a scheduled sudo mount -a
failed (which runs automatically when you have fstab entries), and that caused a process to hang. This process was managed by systemctl, and because fstab processes prior to some other services, the other services couldn't start. Once I fixed a path in fstab, sudo mount -a
stopped failing, and the other services (including `rstudio-server`) started running as normal.