Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip sending of build context without using .dockerignore?

Tags:

docker

Without using a .dockerignore file, is there a way to skip sending of build context when building an image via the following command?

docker build .

In other words, I would like the build context to be empty, without a need to manually create an empty directory that I would then pass to docker build.

like image 953
s3rvac Avatar asked Feb 13 '19 09:02

s3rvac


People also ask

How do I override Dockerignore?

Change App Structure. The only other useful option I can think of is to split out your ADD or COPY into multiple commands so that you don't rely on the the . dockerignore to filter files to the other 3 images. This would probably require your assets directory to be stored outside of your application root.

How can you exclude files and directories from the build context?

Solution Using the . dockerignore file to solve the build context issue. The Docker CLI searches for a file named . dockerignore in the context's root directory before sending it to the Docker daemon. In case the file exists, the CLI excludes directories and files that match its patterns.

Why do we need Dockerignore?

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.

Does Docker Compose use Dockerignore?

Yes, the Dockerfile , docker-compose. yml , and . dockerignore are all used to build the image and spin up a container, however, that's where the purpose of these files stop. They are not used in our app.


1 Answers

You can run

docker build - < Dockerfile

From the official documentation:

This will read a Dockerfile from STDIN without context. Due to the lack of a context, no contents of any local directory will be sent to the Docker daemon.

like image 76
s3rvac Avatar answered Nov 11 '22 01:11

s3rvac