Search code examples
dockerdockerfiledockerignore

Docker ignore not ignoring


I am trying to ignore some files/directories when creating my docker image. I am using a .dockerignore file for this. This file and my Dockerfile are both in my root directory. My .dockerignore file is as follows:

node_modules
.idea
.vscode
.build
.dist
.git
npm-debug.log
*.env
.env
.fleet
nodemon.json
*.code-workspace
typingConventions.md
build
.DS_Store
__tests__

With the file, I'd for example expect there to not be any .env files in my image, but this is not the case. Browsing through the files, I do find /app/core/server/.env.

The contents of my Dockerfile file:

FROM node:18-alpine as builder
WORKDIR /app
RUN npm i pnpm --global
COPY core core
COPY lib lib
COPY sub-projects sub-projects
COPY turbo.json turbo.json
COPY pnpm-workspace.yaml pnpm-workspace.yaml
COPY pnpm-lock.yaml pnpm-lock.yaml
COPY package.json package.json
RUN pnpm install
RUN pnpm run build


FROM node:18-alpine
WORKDIR /app
RUN apk add --no-cache git
RUN apk add  --no-cache ffmpeg
RUN npm i pnpm --global
COPY --from=builder /app/core/server core/server
COPY --from=builder /app/core/front-end/build/ core/server/public
COPY --from=builder /app/lib lib

I am building as follows:

docker build -t server:latest --no-cache .

I checked some other SO questions (here and here) but am still running into my issue.

Is there anything wrong with my ignore or docker files? Or is something else going on?


Solution

  • try with **/.env , and verify your .dockerignore path.