gpt4 book ai didi

Docker - CMD npm start 先于复制所有

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

我正在浏览 Docker 的官方 getting started guide ,还有一部分我不确定:

Dockerfile CMD [ "npm", "start" ]写在COPY . .之前,难道不应该反过来吗? Node.js Dockerfile documentation有不同的顺序

# Use the official image as a parent image.
FROM node:current-slim

# Set the working directory.
WORKDIR /usr/src/app

# Copy the file from your host to your current location.
COPY package.json .

# Run the command inside your image filesystem.
RUN npm install

# Inform Docker that the container is listening on the specified port at runtime.
EXPOSE 8080

# Run the specified command within the container.
CMD [ "npm", "start" ]

# Copy the rest of your app's source code from your host to your image filesystem.
COPY . .

最佳答案

CMD 位于何处实际上并不重要。生成容器时,它将保留由 docker 执行的命令。

由于文件夹的内容不会影响图像内部的步骤,因此将其作为最后一个可用步骤以最佳使用缓存是有意义的(即使它并没有真正影响那里)。

关于Docker - CMD npm start 先于复制所有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61639673/

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