You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docusaurus/docs/dev-docs/installation/docker.md
+35-1Lines changed: 35 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ Strapi does not build any official container images. The following instructions
13
13
:::
14
14
15
15
:::danger
16
-
Strapi applications are not meant to be connected to a pre-existing database, not created by a Strapi application, nor connected to a Strapi v3 database. The Strapi team will not support such attempts. Attempting to connect to an unsupported database may, and most likely will, result in lost data such as dropped tables.
16
+
Strapi applications are not meant to be connected to a pre-existing database, not created by a Strapi application, nor connected to a Strapi v3 database. The Strapi team will not support such attempts. Attempting to connect to an unsupported database may, and most likely will, result in lost data such as dropped tables.
17
17
:::
18
18
19
19
The following documentation will guide you through building a custom [Docker](https://www.docker.com/) container with an existing Strapi project.
@@ -322,6 +322,40 @@ networks:
322
322
323
323
</Tabs>
324
324
325
+
### (Optional) .dockerignore
326
+
327
+
When building Docker images, it's essential to include only the files necessary for running the application inside the container. This is where the `.dockerignore` file comes into play. Similar to how `.gitignore` works for Git, specifying files and directories that should not be tracked or uploaded, `.dockerignore` tells Docker which files and directories to ignore when building an image.
328
+
329
+
Sample `.dockerignore`:
330
+
331
+
```bash
332
+
.tmp/
333
+
.cache/
334
+
.git/
335
+
.env
336
+
build/
337
+
node_modules/
338
+
# Ingoring folders that might be used in starter templates
339
+
data/
340
+
backup/
341
+
```
342
+
343
+
#### Why Use .dockerignore?
344
+
345
+
Including unnecessary files in a Docker build context can significantly slow down the build process. By excluding files and directories like .tmp, .cache, .git, build, node_modules, and .env through .dockerignore, the amount of data sent to the Docker daemon is reduced. This leads to faster build times since Docker has fewer files to process and include in the image.
346
+
347
+
#### Security
348
+
349
+
Excluding files and directories can also enhance the security of the Docker image. Sensitive files, such as `.env`, which might contain environment-specific secrets or credentials, should not be included in Docker images. This prevents accidental exposure of sensitive information.
350
+
351
+
#### Cleaner Images
352
+
353
+
A Docker image cluttered with unnecessary files can lead to potential confusion and issues, especially when the image is shared across teams or used in production. By keeping the image clean and focused only on the essentials, it becomes easier to maintain and troubleshoot.
354
+
355
+
#### Reduced Image Size
356
+
357
+
Smaller Docker images are more efficient to store, transfer, and launch. By excluding non-essential files, the final image size can be significantly reduced, leading to quicker pull and start times, especially in distributed and cloud environments.
358
+
325
359
## Production Environments
326
360
327
361
The Docker image in production is different from the one used in development/staging environments because of the differences in the admin build process in addition to the command used to run the application. Typical production environments will use a reverse proxy to serve the application and the admin panel. The Docker image is built with the production build of the admin panel and the command used to run the application is `strapi start`.
0 commit comments