Let VS Code recognize dockerfiles by filename extension

Normally, dockerfiles all have the same name Dockerfile and VS Code can recognize it. But, in some projects, dockerfiles are named like foo.docker and bar.docker. Vs Code cannot recognize them and treat them as plain text files.

Of course you can use Change language mode by hand to fix it, but it's a bit annoying. How can we do it once and for all?

Update VS Code settings

Open VS Code's settings page, and search files.associations, press Add Item. Then, input the key and value.

Key:

*.docker

Value:

dockerfile

Update VS Code configuration file

If you prefer to edit json file directly, use this:

{
    "files.associations": {
        "*.docker": "dockerfile"
    }
}
Posted on 2022-04-11