What files does the .dockerignore function work in?

I do not understand how .dockerignore works. It is intended for use as follows:

  • First I add something like *.md
  • Then I put this .dockerignore in the container.
  • After that, I launch and enter the container.
  • I create a new file called test.md and transfer this container to a new image.
  • The new image will ignore this file so that it is not in the new container.
+6
source share
3 answers

Before explaining the use of the .dockerignore file, we need to spend a little time understanding what docker build .

Dockers. What happens when I create an image?

When you create an image from a Docker file using the docker build , the daemon creates a context. This context contains everything in the directory in which you executed the command.

What does dockerignore do and why use it?

The .dockerignore file allows .dockerignore to exclude files from the context, such as a .gitignore file, allows you to exclude a file from the git repository.

This helps make the assembly faster and easier by eliminating large files or a repository from the context that are not used in the assembly.

+4
source

docker build has a step where it tar is in the CONTEXT directory and sends it to docker daemon . This is because daemon and client may not be on the same server.

tar and network transfer are why unused files can slow down the build. This happens even if daemon is running locally.

+2
source

Then I put this .dockerignore in the container.

No, do not do this. The .dockerignore file must be located in the same directory as your Dockerfile and is intended to speed up the docker build excluding some of the files that will not be used to create the docker build image during the build.

0
source

All Articles