【问题标题】:Dockerize Nodejs Python Project (Using Dockerfile)Dockerize Nodejs Python 项目(使用 Dockerfile)
【发布时间】:2022-01-23 02:23:39
【问题描述】:

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

原始设置需要此命令,包括 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 install 项目的模块
$ 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

我尝试使用此 dockerfile 内容设置所有内容:

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 run serve)这一点上,我收到类似
TS2305: Module '"../../node_modules/vue/dist/vue"' 的模块错误导出成员“onMounted”。
(查看截图)

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

【问题讨论】:

    标签: python node.js docker npm streamlit


    【解决方案1】:

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

     rm -rf package-lock.json &&
    

    删除它并重建您的图像。

    锁定文件将有助于将项目依赖的 node_modules 保持在所需的版本(即,它有助于在任何地方保持相同的依赖树)

    【讨论】:

    • 这确实有效!谢谢(切换回 2 npm)
    猜你喜欢
    • 1970-01-01
    • 2019-07-22
    • 2020-08-18
    • 2020-05-10
    • 2021-05-06
    • 1970-01-01
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多