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 program go build made 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 Go raw string dockerignore: everything between its backticks, one pattern per line, with no quotes. 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 shop: leaves out shop .git: leaves out .git/config COPY . . copies into /app: main.go go.mod go.sum Dockerfile .dockerignore Nothing that should stay out is in the image, and nothing it needs is missing.
Your task: write the string dockerignore so that it leaves out the secrets file .env, every file ending in .db, the program shop that go build -o shop made, 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 a line of its own between the backticks, with no quotes. On the server, the shop gets its secrets as environment variables and its database at DATABASE_PATH, and the Dockerfile builds its own program from main.go, so the image needs none of them.
Free plan: 30 tutor messages. PRO is unlimited.
