gpt4 book ai didi

node.js - Dockerfile将新创建的文件添加或复制到Docker镜像-没有此类文件或目录

转载 作者:行者123 更新时间:2023-12-02 20:18:14 24 4
gpt4 key购买 nike

我正在尝试运行一个gulp构建过程,该过程将创建在docker构建过程中运行应用程序的已编译和缩小文件。我可以验证gulp进程是否有效,但是一旦docker build完成,服务器就无法访问该build文件。
docker-compose.yml

    build: ${REPO}
depends_on:
- api
ports:
- "8083:8080"
volumes:
- ${REPO}:/usr/src/app
Dockerfile:
FROM python:3.5.1-onbuild
ARG mode=dev
ENV MODE $mode

# Install node.js
RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash
RUN apt-get install -y nodejs
RUN node -v
RUN npm -v
RUN cd $(npm root -g)/npm \
&& npm install fs-extra \
&& sed -i -e s/graceful-fs/fs-extra/ -e s/fs\.rename/fs.move/ ./lib/utils/rename.js


# Install deps for & run gulp build
WORKDIR /usr/src/app/app
RUN npm install
RUN npm install --global gulp-cli
RUN npm rebuild node-sass
RUN gulp //creates /dist, sub-directories and build files in /usr/src/app/app
RUN find ./dist //finds all the newly created files expected

WORKDIR /usr/src/app
ADD /usr/src/app/app/dist/ /usr/src/app/app/dist/
RUN ls
EXPOSE 8080
RUN python3 setup.py install
CMD python3 manage.py ${MODE}
要构建: docker-compose build find
运行: docker-compose up -d
在没有ADD行(从末尾开始4行)的情况下运行,构建不会失败,但是 /dist中的文件不可用于该应用程序。使用此行运行,它在 ADD行失败:
Step 23 : ADD /usr/src/app/app/dist/ /usr/src/app/app/dist/
ERROR: Service 'find' failed to build: lstat usr/src/app/app/dist/: no such file or directory
我也尝试过:
ADD ./app/dist /usr/src/app/app/dist/
它给出了与上述相同的错误消息。 (尽管这对我来说很有意义,因为dist文件最初不在我的计算机上。)
试:
ADD /usr/src/app/app/dist/* /usr/src/app/app/dist/
给我:
ERROR: Service 'find' failed to build: No source files were specified
我怀疑我对上下文和中间容器有误解,但我没有主意。

最佳答案

看一下https://docs.docker.com/engine/reference/builder/#/volume中的卷

The VOLUME instruction creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers.



这将覆盖在构建中创建的新文件夹。

您必须从 volumes中删除 docker-compose.yml,因此无需在 ADD中使用 Dockerfile

关于node.js - Dockerfile将新创建的文件添加或复制到Docker镜像-没有此类文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40849794/

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