admin管理员组文章数量:1345057
I have a simple Typescript application that I want to package in a Docker image. This is the Dockerfile
:
# Stage 1: Build Stage
FROM node:lts AS builder
WORKDIR /app
# Copy package files and install dependencies
COPY package*.json ./
RUN npm ci
# Copy the rest of the source code
COPY . .
# Build the application (assumes a "build" script in package.json)
RUN npm run build
# Remove devDependencies for a leaner final image
RUN npm prune --production
# Stage 2: Runner Stage
FROM node:lts-alpine
WORKDIR /app
# Set environment variable for production
ENV NODE_ENV=production
# Copy only the necessary files from the builder stage
COPY --from=builder /app/package.json ./
COPY --from=builder /app/package-lock.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
# Expose port if needed (uncomment and set appropriate value)
# EXPOSE 3000
# Start the application
CMD ["node", "dist/server.js"]
The issue is, when I make a change in the Typescript files and run docker build ...
, the dist
folder content does not update.
I also tried it with docker build .... --no-cache
, same results. The only thing that seems to work it to remove all old images.
This is the output of the docker build:
> docker build --no-cache -t api-service:latest .
[+] Building 5.8s (19/19) FINISHED docker:desktop-linux
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 881B 0.0s
=> [internal] load metadata for docker.io/library/node:lts-alpine 0.3s
=> [internal] load metadata for docker.io/library/node:lts 0.3s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 1.83kB 0.0s
=> [builder 1/7] FROM docker.io/library/node:lts@sha256:c7fd844945a76eeaa83cb372e4d289b4a30b478a1c80e16c685b62c54156285b 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 2.31kB 0.0s
=> [stage-1 1/6] FROM docker.io/library/node:lts-alpine@sha256:9bef0ef1e268f60627da9ba7d7605e8831d5b56ad07487d24d1aa386336d1944 0.0s
=> CACHED [builder 2/7] WORKDIR /app 0.0s
=> CACHED [stage-1 2/6] WORKDIR /app 0.0s
=> [builder 3/7] COPY package*.json ./ 0.0s
=> [builder 4/7] RUN npm ci 3.0s
=> [builder 5/7] COPY . . 0.0s
=> [builder 6/7] RUN npm run build 1.0s
=> [builder 7/7] RUN npm prune --production 1.3s
=> [stage-1 3/6] COPY --from=builder /app/package.json ./ 0.0s
=> [stage-1 4/6] COPY --from=builder /app/package-lock.json ./ 0.0s
=> [stage-1 5/6] COPY --from=builder /app/node_modules ./node_modules 0.1s
=> [stage-1 6/6] COPY --from=builder /app/dist ./dist 0.0s
=> exporting to image 0.1s
=> => exporting layers 0.0s
=> => writing image sha256:2970593b3ae3e6b69d07d932df159bae0534a6bc5f37caae585cd39bb391f2b9
```
本文标签: dockerMultiStage Dockerfile Caching Build FilesStack Overflow
版权声明:本文标题:docker - Multi-Stage Dockerfile Caching Build Files - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743808088a2542547.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论