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, Maven's build in target, 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 Java array dockerignore: each string in it is one line of the file. 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 target: leaves out target/shop.jar .git: leaves out .git/config COPY . . copies into /app: pom.xml src/main/java/shop/ShopApplication.java Dockerfile .dockerignore Nothing that should stay out is in the image, and nothing it needs is missing.
Your task: fill the array dockerignore so that it leaves out the secrets file .env, every file ending in .db, the target folder and the .git folder, and nothing the shop needs.
Assignment
Follow the Coding Tutorial to write the four lines of the shop's .dockerignore.
Hint
Each pattern is its own string in the array, with a comma after it. On the server, the shop gets its secrets as environment variables and its database at DATABASE_PATH, and the Dockerfile builds its own jar with mvn package, so the image needs none of them.
Free plan: 30 tutor messages. PRO is unlimited.
