Dockerize Nodejs Python 项目(使用 Dockerfile)

Dockerize Nodejs Python Project (Using Dockerfile)

我目前正在与 streamlit 一起撰写网络应用程序的学士论文。 但是,我想在这里使用 vue 模板 from this github 存储库。 为此,我需要安装 NodejsPython 并使用 npm 或 yarn github 存储库中需要的包。我想 docker 将所有内容都放在一个容器中。

原始设置需要此命令,包括 Python 3.6+、Node.jsnpm

  1. py3 env 和 streamlit 包
$ python3 -m venv venv  # create venv

$ . venv/bin/activate   # activate venv

$ pip install streamlit # install streamlit
  1. npm 安装项目的模块
$ cd my_component/frontend

$ npm install    # Install npm dependencies

$ npm run serve  # Start the Webpack dev server
$ . venv/bin/activate  # activate the venv you created earlier

$ streamlit run my_component/__init__.py  # run the example

我试图用这个 docker 文件内容设置所有内容:

FROM ubuntu:20.04

ENV TZ=Europe
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

EXPOSE 8501
WORKDIR /app
COPY requirements.txt ./requirements.txt

RUN apt update -y  && \
    apt install -y git && \
    apt install -y curl  && \
    apt install -y python3-pip && \
    pip3 install -r requirements.txt && \
    curl -sL https://deb.nodesource.com/setup_17.x | bash  && \
    apt install -y nodejs  && \
    node -v  && \
    npm -v  && \
    git clone https://github.com/andfanilo/streamlit-component-template-vue && \
    cd streamlit-component-template-vue/my_component/frontend && \
    rm -rf node_modules && \
    export NODE_OPTIONS=--openssl-legacy-provider && \
    npm i && \
    npm run build && \  
    ls -a
CMD streamlit run streamlit-component-template-vue/my_component/__init__.py



但是在“yarn build”(或 yarn 运行 serve)这一点上,我收到模块错误,例如
TS2305: 模块 '"../../node_modules/vue/dist/vue"' 没有导出成员 'onMounted'.
(检查屏幕截图)

我做错了什么?没有 docker,在我的本地机器上,一切都按预期工作!

我最确定问题是由以下行引起的:

 rm -rf package-lock.json &&

删除它并重建您的图像。

锁定文件将有助于 node_modules 项目依赖于他们想要的版本(即它有助于在任何地方保持相同的依赖关系树)