Skip to content

Running in a docker instance? Currently have kernel death #7

@perllaghu

Description

@perllaghu

Has anyone got this working in a jupyter notebook in a docker image?

I'm rebuilding a Jupyter Notebook Docker image with the stata kernel installed.
It worked fine with Stata 16 (I was using stata_kernel) and I thought all was well with Stata 17 - however I recently discovered I could not get that kernel to display images.

I've switched to pystata-kernel, and now I'm just getting Kernel Restarting errors for the simplest things.

(I should note, at this point, that my notebook-servers are built to run in a kubernetes cloud, with the users home directory mounted at /home/jovyan - so anything built into /home/jovyan gets lost.)

Dockerfile

FROM alpine:3.15.0

WORKDIR /tmp
RUN wget -nv http://some.internal.file.server/files/Stata17Linux64.tar.gz

#### step 1
FROM jupyter/minimal-notebook:2022-05-01
USER root
RUN apt-get update \
  && apt-get install -yq --no-install-recommends \
    expect \
    libncurses5 \
    libtinfo5 \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/*

WORKDIR /tmp
COPY --from=0 /tmp/Stata17Linux64.tar.gz .

RUN mkdir statafiles \
    && cd statafiles \
    && tar -zxf /tmp/Stata17Linux64.tar.gz
COPY stata-notebook/install-scripts/. /usr/local/bin/.
RUN mkdir /usr/local/stata -p
WORKDIR /usr/local/stata

ENV STATA_NUMBER="1234"
ENV STATA_CODE="abcd e\$gh"
ENV STATA_AUTHORIZATION="foo"

# Instal stata
RUN /usr/local/bin/interact_stata.sh
RUN /usr/local/bin/interact_stinit.sh
ENV PATH=/usr/local/stata:/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# Install stata kernel
USER $NB_USER
RUN mkdir -p $HOME/.pystata-kernel.conf \
    && chown -R $NB_USER $HOME/.pystata-kernel.conf
RUN pip install pystata-kernel \
    && python -m pystata-kernel.install
USER root
RUN mkdir -p /usr/local/share/jupyter/kernels \
    && mv $HOME/.local/share/jupyter/kernels/pystata /usr/local/share/jupyter/kernels

# Remove temporary stata files
RUN rm -rf /tmp/statafiles && rm /tmp/Stata17Linux64.tar.gz
RUN chown -R $NB_UID:$NB_GID $HOME

COPY docker-entrypoint.sh /usr/local/bin/

RUN find $CONDA_DIR -not -user $NB_USER -exec chown $NB_UID:$NB_GID {} \;
WORKDIR $HOME
USER $NB_USER

The docker-entrypoint.sh is so I can create the config file in a users home directory:

tee ~/.stata_kernel.conf << END
[stata_kernel]

# Path to stata executable. If you type this in your terminal, it should
# start the Stata console
stata_path = /usr/local/stata/stata-se

# Directory to hold temporary images and log files
cache_directory = ~/.stata_kernel_cache

# Whether autocompletion suggestions should include the closing symbol
autocomplete_closing_symbol = False

# # Extension and format for images
# graph_format = svg

# Scaling factor for graphs
graph_scale = 1

# List of user-created keywords that produce graphs.
# Should be comma-delimited.
user_graph_keywords = coefplot,vioplot
END

exec "$@"

Everything builds fine, the notebook-server starts fine, and a notebook-document starts for the stata kernel.

The test

I have tried in both the Classic and Lab interfaces - both exhibit the same issue

Even running the simplest code - display "Hello, world!" - I get a Kernel Restarting error popup (The kernel for Untitled.ipynb appears to have died. It will restart automatically.)

Log file

This is what I get in my docker log-file:

[I 2022-08-24 13:59:17.186 LabApp] Build is up to date
[I 2022-08-24 13:59:22.669 ServerApp] Kernel started: 7ccbc29e-b51f-4496-939f-8bc0eed9b04b
[I 2022-08-24 14:00:05.390 ServerApp] Creating new notebook in 
[I 2022-08-24 14:00:05.448 ServerApp] Writing notebook-signing key to /home/jovyan/.local/share/jupyter/notebook_secret
[I 2022-08-24 14:00:05.791 ServerApp] Kernel started: 693f97e5-3819-4656-b3b5-d3890bd5ab61
[I 2022-08-24 14:00:17.780 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (1/5), new random ports
[W 2022-08-24 14:00:17.780 ServerApp] kernel 693f97e5-3819-4656-b3b5-d3890bd5ab61 restarted
[I 2022-08-24 14:00:17.783 ServerApp] Starting buffering for 693f97e5-3819-4656-b3b5-d3890bd5ab61:c89c684f-b42b-4234-8851-8f7b87d1aa32
[I 2022-08-24 14:00:17.810 ServerApp] Restoring connection for 693f97e5-3819-4656-b3b5-d3890bd5ab61:c89c684f-b42b-4234-8851-8f7b87d1aa32

Looking for help/advise on making this work...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions