首页 > 解决方案 > 如何使用带有 .devcontainer.json 的 Docker 在 VSCode 中启动 jupyter lab

问题描述

我正在尝试在由 Docker 封装的 VSCode 远程服务器中启动 jupyter 实验室,但出现错误提示

无法为内核 Python 3.8.5 64 位启动会话。选择另一个内核来启动。

我在工作区目录中设置了 Dockerfile 和 .devcontainer.json。我是否还需要 docker-compose.yaml 文件来进行 jupyter 实验室设置(如端口转发)?或者我可以用 .devcontainer.json 文件处理和替换 docker-compose 文件?

Dockerfile:

FROM python:3.8
RUN apt-get update --fix-missing && apt-get upgrade -y
# Set Japanese UTF-8 as locale so Japanese can be used
RUN apt-get install -y locales \
    && locale-gen ja_JP.UTF-8

ENV LANG ja_JP.UTF-8
ENV LANGUAGE ja_JP:ja
ENV LC_ALL ja_JP.UTF-8

# RUN apt-get install zsh -y && \
#     chsh -s /usr/bin/zsh

# Install zsh with theme and some plugins
RUN sh -c "$(wget -O- https://raw.githubusercontent.com/deluan/zsh-in-docker/master/zsh-in-docker.sh)" \
    -t mrtazz \
    -p git -p ssh-agent

RUN pip install jupyterlab
RUN jupyter serverextension enable --py jupyterlab

WORKDIR /app

CMD ["bash"]

.devcontainer.json

{
"name": "Python 3.8",
"build": {
    "dockerfile": "Dockerfile",
    "context": ".."

},

    // Uncomment to use docker-compose
    // "dockerComposeFile": "docker-compose.yml",
    // "service": "dev",


    // Set *default* container specific settings.json values on container create.
    "settings": {
        "terminal.integrated.shell.linux": "/bin/bash",
        "python.pythonPath": "/usr/local/bin/python",
        "python.linting.enabled": true,
        "python.linting.pylintEnabled": true,
        "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
        "python.formatting.blackPath": "/usr/local/py-utils/bin/black",
        "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
        "python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
        "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
        "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
        "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
        "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
        "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
    },
    // Add the IDs of extensions you want installed when the container is created.
    "extensions": [
        "ms-python.python",
        "teabyii.ayu",
        "jeff-hykin.better-dockerfile-syntax",
        "coenraads.bracket-pair-colorizer-2",
        "file-icons.file-icons",
        "emilast.logfilehighlighter",
        "zhuangtongfa.material-theme",
        "ibm.output-colorizer",
        "wayou.vscode-todo-highlight",
        "atishay-jain.all-autocomplete",
        "amazonwebservices.aws-toolkit-vscode",
        "hookyqr.beautify",
        "phplasma.csv-to-table",
        "alefragnani.bookmarks",
        "mrmlnc.vscode-duplicate",
        "tombonnike.vscode-status-bar-format-toggle",
        "donjayamanne.githistory",
        "codezombiech.gitignore",
        "eamodio.gitlens",
        "zainchen.json",
        "ritwickdey.liveserver",
        "yzhang.markdown-all-in-one",
        "pkief.markdown-checkbox",
        "shd101wyy.markdown-preview-enhanced",
        "ionutvmi.path-autocomplete",
        "esbenp.prettier-vscode",
        "diogonolasco.pyinit",
        "ms-python.vscode-pylance",
        "njpwerner.autodocstring",
        "kevinrose.vsc-python-indent",
        "mechatroner.rainbow-csv",
        "msrvida.vscode-sanddance",
        "rafamel.subtle-brackets",
        "formulahendry.terminal",
        "tyriar.terminal-tabs",
        "redhat.vscode-yaml"
    ],

    // Use 'forwardPorts' to make a list of ports inside the container available locally.
    "forwardPorts": [8888],

    // Use 'postCreateCommand' to run commands after the container is created.
    // "postCreateCommand": "pip3 install -r requirements.txt",

    // Comment out to connect as root instead.
    // "remoteUser": "myname",

    "shutdownAction": "none"
}

标签: pythondockervisual-studio-codedocker-composejupyter-lab

解决方案


推荐阅读