Dockerfile 构建 jupyter 镜像
Dockerfile && jupyterlab¶
下面是一个 dockerfile 来构建 jupyterlab 镜像
FROM ubuntu:22.04
# 设置环境变量
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 \
PATH=/usr/local/miniconda3/bin:$PATH \
DEBIAN_FRONTEND=noninteractive
# 安装基本依赖
RUN apt-get update && apt-get install -y \
wget \
curl \
bzip2 \
ca-certificates \
libglib2.0-0 \
libxext6 \
libsm6 \
libxrender1 \
git \
python3 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# 设置 shell 为 bash,支持 conda activate
SHELL ["/bin/bash", "-c"]
ENV SHELL=/bin/bash
# 下载并安装 Miniconda
ENV CONDA_DIR=/usr/local/miniconda3
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && \
mkdir -p $CONDA_DIR && \
bash /tmp/miniconda.sh -b -u -p $CONDA_DIR && \
rm /tmp/miniconda.sh && \
$CONDA_DIR/bin/conda clean -afy
RUN conda init bash && \
conda create -y -n jupyter -c conda-forge python=3.11 jupyterlab jupyterlab-language-pack-zh-CN && \
echo "source activate jupyter" >> ~/.bashrc
# 显示 JupyterLab 启动端口
EXPOSE 8888
# 设置默认工作目录
WORKDIR /workspace
# 默认启动时进入 bash
CMD ["/bin/bash", "-c", "source activate jupyter && jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root --NotebookApp.token='' --NotebookApp.password=''"]
Dockerfile 基础依赖¶
- ubuntu22.04 基础镜像
- Minconda
- jupyter
运行¶
docker run -it --rm -p 80:8888 crpi-4lzb9eicmxfps53y.cn-beijing.personal.cr.aliyuncs.com/common_runtime/miniconda3:v1