jupyterlab 컨테이너에서 terminal의 기본 shell을 bash로 설정하는 방법

박종배·2023년 7월 5일
0
post-thumbnail

개요

kubeflow notebook에서 jupyter를 쓸 때 terminal의 기본 쉘이 sh로 되어 있어서 매번 bash로 변경해줘야 하는 번거로움이 있음.

Dockerfile에서 jupyter 설정으로 기본 쉘을 bash로 바꿔보자.

Dockerfile 작성

FROM pytorch/pytorch:1.13.1-cuda11.6-cudnn8-runtime
WORKDIR /home/jovyan
USER root
RUN pip install jupyter -U && pip install jupyterlab

RUN apt-get update && apt-get install -yq --no-install-recommends \
    apt-transport-https \
    build-essential \
    bzip2 \
    ca-certificates \
    curl \
    g++ \
    git \
    gnupg \
    graphviz \
    locales \
    lsb-release \
    openssh-client \
    sudo \
    unzip \
    vim \
    wget \
    zip \
    emacs \
    python3-pip \
    python3-dev \
    python3-setuptools \
    git \
    wget \
    libgl1-mesa-glx \
    && apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
RUN echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
RUN apt-get update
RUN apt-get install -y kubectl

RUN pip install jupyterlab && \
    jupyter serverextension enable --py jupyterlab --sys-prefix

RUN pip install kubernetes kfp redis
RUN pip install kubeflow-katib

RUN /opt/conda/bin/python -m pip install -U pip

ADD requirements.txt /tmp/requirements.txt

RUN pip install -r /tmp/requirements.txt

ARG NB_USER=jovyan

ENV NB_PREFIX /
ENV NB_USER $NB_USER
ENV NB_UID=1000
ENV HOME /home/$NB_USER
ENV NB_PREFIX /

RUN useradd -M -s /bin/bash -N -u ${NB_UID} ${NB_USER} \
    && mkdir -p ${HOME} \
    && chown -R ${NB_USER}:users ${HOME} \
    && chown -R ${NB_USER}:users /usr/local/bin \
    && groupadd -g 1337 mygroup

EXPOSE 8888
USER jovyan

RUN jupyter lab --generate-config \
    && echo '\
c.NotebookApp.terminado_settings = { "shell_command": ["/bin/bash"] }' \
    >> /home/jovyan/.jupyter/jupyter_lab_config.py

CMD ["/bin/bash","-c", "jupyter lab --notebook-dir=/home/${NB_USER} --ip=0.0.0.0 --no-browser --allow-root --port=8888 --NotebookApp.token='' --NotebookApp.password='' --NotebookApp.allow_origin='*' --NotebookApp.base_url=${NB_PREFIX}"]
  • 다른 부분은 제외하고 마지막 부분에 69:72 라인을 보자.
  • jupyter lab —generate-config로 /home/jovyan/.jupyter/jupyter_lab_config.py 기본 설정 파일을 생성. 안에 내용은 주피터 설정의 기본값이 주석으로 들어가 있으므로 그냥 생성만 한다고 보면 됨.
  • echo 부분에서 terminal 쉘을 bash로 설정하는 내용을 /home/jovyan/.jupyter/jupyter_lab_config.py 에 추가함.

위에 Dockerfile을 기준으로 build해서 사용하면 됨.

노트북 생성 및 확인

  • 위와 같이 정상적으로 bash를 기본 terminal shell로 사용함.
profile
기록하는 엔지니어 되기 💪

0개의 댓글