Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the files that the .dockerignore works on?

Tags:

docker

I don't really understand how .dockerignore works. Is it intended to be used like the following:

  • First I add somethings in it such as *.md
  • Then I put this .dockerignore into the container.
  • After that I run and enter the container.
  • I create a new file named test.md and commit this container to the new image.
  • The new image will ignore this file so it will not be in the new container.
like image 667
大易归真 Avatar asked Aug 03 '15 14:08

大易归真


People also ask

Where is the .dockerignore file?

dockerignore file is on the root directory of your context, it will ignore it if it is somewhere in the subfolder.

Why do we need Docker ignore?

dockerignore file allows you to exclude files from the context like a . gitignore file allow you to exclude files from your git repository. It helps to make build faster and lighter by excluding from the context big files or repository that are not used in the build.

What is difference between ADD and copy in Dockerfile?

COPY is a docker file command that copies files from a local source location to a destination in the Docker container. ADD command is used to copy files/directories into a Docker image. It only has only one assigned function. It can also copy files from a URL.


Video Answer


3 Answers

Before explaining the use of the .dockerignore file we must spend a little time understanding what docker build does.

Docker build. What does happen when I build an image ?

When you build an image from a Dockerfile using the docker build command the daemon will create a context. That context contains everything in the directory you executed the command in.

What does .dockerignore do and why use it?

The .dockerignore file allows you to exclude files from the context like a .gitignore file allow you to exclude files from your git repository.

It helps to make build faster and lighter by excluding from the context big files or repository that are not used in the build.

like image 55
Regan Avatar answered Oct 06 '22 04:10

Regan


docker build has a step where it tars up the CONTEXT directory and sends it to the docker daemon. This is because the daemon and client might not exist on the same server.

The tar and network send is why unused files can slow down the build. These happen even if the daemon runs locally.

like image 33
Dale Jung Avatar answered Oct 06 '22 04:10

Dale Jung


Then I put this .dockerignore in container.

nope, don't do that. The .dockerignore file is meant to be in the same directory as your Dockerfile and is intended to speed up the docker build command by excluding at build time some of the files that won't be used to build the docker image.

like image 1
Thomasleveil Avatar answered Oct 06 '22 06:10

Thomasleveil