In your Dockerfile, COPY . . copies the whole shop folder into the image. But the folder holds more than the shop: the secrets in .env, a test database, the bin and obj folders that dotnet fills on your computer, the git history. Anyone who gets an image can read every file in it.
A file named .dockerignore, next to the Dockerfile, lists what docker build must leave out, one pattern per line. A name leaves out that file, or that folder and everything in it. A * stands for any characters. For example, a project that writes log files and keeps a scratch folder could use:
*.log
scratch
Here the file's text is the C# list dockerignore: one string per line, each with a comma after it. The check reads it, says what each line leaves out, then lists what COPY . . would copy into /app. When your file is done, it prints:
.dockerignore: .env: leaves out .env *.db: leaves out shop.db bin: leaves out bin/Debug/net8.0/shop.dll obj: leaves out obj/project.assets.json .git: leaves out .git/config COPY . . copies into /app: Program.cs shop.csproj Dockerfile .dockerignore Nothing that should stay out is in the image, and nothing it needs is missing.
Your task: fill the list dockerignore so that it leaves out the secrets file .env, every file ending in .db, the bin and obj folders and the .git folder, and nothing the shop needs.
Assignment
Follow the Coding Tutorial to write the five lines of the shop's .dockerignore.
Hint
Each pattern is its own string in the list, with a comma after it. On the server, the shop gets its secrets as environment variables and its database at DATABASE_PATH, and the image builds its own bin and obj with dotnet publish, so it needs none of yours.
Free plan: 30 tutor messages. PRO is unlimited.
