gpt4 book ai didi

python - 用于 Node 模块和 python 要求的 Docker 缓存

转载 作者:太空宇宙 更新时间:2023-11-04 12:08:30 24 4
gpt4 key购买 nike

我有一个 dockerfile,我正在尝试使用 COPY。 .

我有一个 dockerfile,我已尽最大努力复制本地依赖项并使用 docker 缓存。

现在我有使用缓存而不是 node_modules 的 python 要求。

FROM itsspeed/ubuntu-16.04-python
#FROM python:2.7-stretch
RUN apt-get update && apt-get install -y \
--no-install-recommends curl sudo apt-transport-https
RUN apt-get install libssl-dev -y
RUN python --version

#VOLUME "/usr/local/app"

# Set up C++ dev env
RUN apt-get update && \
apt-get dist-upgrade -y && \
apt-get install gcc-multilib g++-multilib cmake wget -y && \
apt-get clean autoclean && \
apt-get autoremove -y
#wget -O /tmp/conan.deb -L https://github.com/conan-io/conan/releases/download/0.25.1/conan-ubuntu-64_0_25_1.deb && \
#dpkg -i /tmp/conan.deb


RUN curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
RUN apt-get install -y nodejs
RUN apt-get install -y build-essential
#RUN apt-get install -y npm
RUN npm -v

RUN mkdir -p /usr/local/app

COPY nlu-server/requirements.txt /usr/local/app/nlu-server/requirements.txt
WORKDIR /usr/local/app/nlu-server
RUN pip install -r requirements.txt
COPY . /usr/local/app/nlu-server
WORKDIR /usr/local/app


COPY package.json /usr/local/app
RUN ["npm", "install"]
COPY . .



RUN echo "/usr/local/app/dm-prod/lib" > /etc/ld.so.conf.d/mythrift.conf
RUN echo "/usr/lib/x86_64-linux-gnu" >> /etc/ld.so.conf.d/mythrift.conf
RUN echo "/usr/local/lib64" >> /etc/ld.so.conf.d/mythrift.conf
RUN ldconfig

EXPOSE 9090
RUN chmod +x dm-prod/dm3
RUN ldd dm-prod/dm3
RUN ["chmod", "+x", "dm-prod/dm3"]
RUN ["chmod", "777", "policy"]
RUN ls -al .
CMD ["nodejs", "app.js"]

这是来自 docker 输出的一个片段,我在其中重建了一个没有任何更改的容器,正如您所看到的,正在重新安装 Node 模块。好消息,虽然 python 要求正在使用缓存。

Step 7/29 : RUN apt-get install -y nodejs
---> Using cache
---> 0dd67f16bd8d
Step 8/29 : RUN apt-get install -y build-essential
---> Using cache
---> 24c15ed4a512
Step 9/29 : RUN npm -v
---> Using cache
---> 2365c20cc909
Step 10/29 : RUN mkdir -p /usr/local/app
---> Using cache
---> 409fc9242250
Step 11/29 : COPY nlu-server/requirements.txt /usr/local/app/nlu-server/requirements.txt
---> Using cache
---> e8cb2304b033
Step 12/29 : WORKDIR /usr/local/app/nlu-server
---> Using cache
---> ae5f314a10d6
Step 13/29 : RUN pip install -r requirements.txt
---> Using cache
---> 348d0db50e78
Step 14/29 : COPY . /usr/local/app/nlu-server
---> bbe2e0efcf23
Step 15/29 : WORKDIR /usr/local/app
Removing intermediate container d9adf038e20f
---> 8cc90b3a07a6
Step 16/29 : COPY package.json /usr/local/app
---> 9c9a0b6b6e32
Step 17/29 : RUN ["npm", "install"]
---> Running in 10feae860449
npm WARN deprecated jade@1.11.0: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated formatio@1.1.1: This package is unmaintained. Use @sinonjs/formatio instead
npm WARN deprecated constantinople@3.0.2: Please update to at least constantinople 3.1.1
npm WARN deprecated transformers@2.1.0: Deprecated, use jstransformer

> nodemon@1.17.3 postinstall /usr/local/app/node_modules/nodemon
> node -e "console.log('\u001b[32mLove nodemon? You can now support the project via the open collective:\u001b[22m\u001b[39m\n > \u001b[96m\u001b[1mhttps://opencollective.com/nodemon/donate\u001b[0m\n')" || exit 0

Love nodemon? You can now support the project via the open collective:
> https://opencollective.com/nodemon/donate

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 919 packages in 18.65s
Removing intermediate container 10feae860449
---> d506ee33621f
Step 18/29 : COPY . .
---> 7606470b8292

最佳答案

对于所有好奇的人来说,那些有几层依赖关系的人需要缓存。

这里的行是我安装 Node 模块

WORKDIR /usr/local/app


COPY package.json /usr/local/app
RUN ["npm", "install"]
COPY . .

我实际上需要将工作目录重置为根目录以复制包 json。

WORKDIR /
COPY package.json /usr/local/app/package.json
WORKDIR /usr/local/app
RUN ["npm", "install"]
COPY . .

之前的代码是从同一个文件夹复制到同一个文件夹,本质上是使它成为一个新的、更改过的文件,从而触发 npm 安装。最好的

关于python - 用于 Node 模块和 python 要求的 Docker 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49780822/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com