16

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
  • 83,933
  • 102
  • 303
  • 431
  • 1
    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
  • 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. – emix Apr 26 '18 at 13:01

6 Answers6

9

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

About Docker

Docker is the company driving the container movement and the only container platform provider to address every application across the hybrid cloud. Today’s businesses are under pressure to digitally transform but are constrained by existing applications and infrastructure while rationalizing an increasingly diverse portfolio of clouds, datacenters and application architectures. Docker enables true independence between applications and infrastructure and developers and IT ops to unlock their potential and creates a model for better collaboration and innovation. More on

benito
  • 599
  • 5
  • 12
  • 10
    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
  • 6
    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
9

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
  • 568
  • 6
  • 14
3

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

Wolfe
  • 41
  • 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
  • 9,983
  • 12
  • 32
  • 52
-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
  • 197
  • 11
  • 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
  • 151,199
  • 17
  • 111
  • 216