23

Visual Studio Code (1.22.2) offers a file extension named .dockerfile in the the save dialog. What is a file with this extension? A Dockerfile is in all documentation and examples, that I've seen so far, only called Dockerfile.

enter image description here

If I enter Dockerfile as a file name, a file named Dockerfile.dockerfile is created.

deamon
  • 89,107
  • 111
  • 320
  • 448
  • 2
    Have you tried it to see if the file actually gets a `.dockerfile` extension? Perhaps it's just an UI thing (e.g. the part inside the parentheses couldn't be left empty).? – Michael Apr 26 '18 at 12:06
  • 1
    Yes, I've tried it. If I enter `Dockerfile` as a file name, a file named `Dockerfile.dockerfile` is created. I'll add that to the question. – deamon Apr 26 '18 at 12:57
  • 1
    Windows operates on files with extensions so my guess is they introduced such extension by themselves. Docker implies the `Dockerfile` name, but you can name the file as you want, as long as you provide it's name to the related docker command. – Mike Doe Apr 26 '18 at 13:01

6 Answers6

14

It appears that "*.dockerfile" is simply an alternative to the conventional "Dockerfile" name. This is perhaps useful if you want to keep a collection of dockerfiles in the same directory. Note the -f/--file option in docker help build:

-f, --file string Name of the Dockerfile (Default is 'PATH/Dockerfile')

In other words, you are not required to use the name "Dockerfile", and the VSCode extension will correctly syntax-highlight any file ending in ".dockerfile".

gwk
  • 638
  • 7
  • 15
  • This is the correct answer. If you have multiple dockerfiles in a single directory, you can give those abitrary names with the `.dockerfile` extension, and then build those by running `docker build . -f "filename.dockerfile"` – Tijmen Aug 16 '23 at 11:49
10

Dockerfile

A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession. Docker images are the basis of containers. An Image is an ordered collection of root filesystem changes and the corresponding execution parameters for use within a container runtime. An image typically contains a union of layered filesystems stacked on top of each other. An image does not have state and it never changes.More on

Dockerfile extension

A Dockerfile has no extension . if your using docker on docker on windows use notepad ++ to create a dockerfile while saving select “All type “ and save the file name as “Dockerfile”.

Mongodb/Dockerfile

enter image description here

mhsmith
  • 6,675
  • 3
  • 41
  • 58
benito
  • 655
  • 6
  • 12
  • 14
    This doesn't answer the question. As you can see, there _is_ a `.dockerfile` extension, even if docker files usually don't have one. – deamon Jun 15 '18 at 07:03
  • 10
    This answer reads like a mix of some statements not answering the question and some statements advertising docker. – iron9 Jul 28 '21 at 13:49
  • Docker can deal with files simply named `Dockerfile`, not requiring an extension. However, let's say you have a directory with 2 or more different dockerfiles, you can give those an arbitrary name with the `.dockerfile` extension, and then build those by running `docker build . -f "filename.dockerfile"`. Your answer is therefore incomplete at best. – Tijmen Aug 16 '23 at 11:48
5

Using the .dockerfile extension tells VSCode that the file is a DockerFile for code highlighting and linting

Wolfe
  • 61
  • 1
  • 1
1

What worked for me was to save the file in VS Code as a Dockerfile. But, you need to remove the .dockerfile extension that VS Code puts on it before running the $docker-compose up command:

enter image description here

Samuel Philipp
  • 10,631
  • 12
  • 36
  • 56
-1

Even though VSCode can deal with extensionless files just fine, some major parts of the Windows operating system can't. Try double clicking a Dockerfile (without extension) in the Windows Explorer. You will always be asked which program you want to open it in because Windows can't map extensionless files to a default program.

My guess is that because of this problem, Microsoft would like for all files to have an extension and uses VSCode to nudge people towards using a file extension for Dockerfiles, ignoring the fact that this contradicts the de facto standard.

iron9
  • 397
  • 2
  • 12
  • Double click is for running executable programs. What do you expect to happen when you double click on it? Build the image? Run the image? Or just open a text editor? – OneCricketeer Dec 13 '21 at 03:12
  • @OneCricketeer You can easily configure Windows to open any file (with a file extension) with any program on a double click. You cannot do that with a file which has no file extension. I consider your first sentence to be incorrect/incomplete. As to your question: I expect the default program for a Dockerfile to be a text editor. – iron9 Dec 13 '21 at 18:17
-3

Dockerfile doesn't have any extensions.
As you can see from hte documentation, https://docs.docker.com/compose/gettingstarted/, it doesn't have any extensions.

Dockerfile

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245