Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Location for common .dockerignore file

I’d like a common .dockerignore file, "outside" a build context (which I assume is the directory in which the Dockerfile is located).

So instead of this:

project/
  client/
      src/
      .dockerignore
      Dockerfile
  server/
      src/
      .dockerignore
      Dockerfile

I prefer this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

project/
  client/
      src/
      Dockerfile
  server/
      src/
      Dockerfile
  .dockerignore

Is that allowed? Will it walk up the filesystem until root, looking for an ignore file (the way it’s commonly done by other cli tools), or must it be at the same level as the Dockerfile?

There have been changes to the mechanism in recent docker versions, e.g. for custom Dockerfile.foo.dockerignore files, which must be placed at the same level as the Dockerfile.foo. So I’m unsure what is the current rule, and the docs don’t explain.

I’m using the latest version, docker 24.0.5.

>Solution :

From your docs link:

Before the docker CLI sends the context to the docker daemon, it looks for a file named .dockerignore in the root directory of the context.

From build context:

The build context is the argument that you pass to the build command. When your build context is a local directory, a remote Git repository, or a tar file, then that becomes the set of files that the builder can access during the build.

From docker build:

By default the docker build command will look for a Dockerfile at the root of the build context. The -f, –file, option lets you specify the path to an alternative file to use instead.

So you should be able to do:

docker build -f client <path_to_project>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading