---
title: "Dockerfiles, Compose Files and Kubernetes YAML in Neovim"
canonical: "https://mnafshin.info/devtools/12-docker-and-kubernetes-files/"
author: "Afshin Amini"
date: 2026-11-29
---
# Dockerfiles, Compose Files and Kubernetes YAML in Neovim

A Spring Boot service rarely ships alone. Next to the Java code sit a `Dockerfile` that builds its image, a Compose file that starts a database for local work, and Kubernetes manifests that deploy it. These are files you edit in the same editor, and mistakes in them are easy to make and slow to find. LazyVim can check all three while you type. This part covers only that editor support; what containers and Kubernetes objects are, and how to run them, is covered in the [Kubernetes section](/k8s/).

## Two extras do the work

- **`lang.docker`** installs `dockerls`, a language server for Dockerfiles, and `hadolint`, a Dockerfile linter.
- **`lang.yaml`** installs `yamlls`, the YAML language server. It validates YAML against JSON schemas and has a built-in schema store that recognises many well-known files, including Compose files.

Enable both in `:LazyExtras` and restart. Mason installs the tools on the next start.

## Check a Dockerfile

The companion code has no Dockerfile yet, so we wrote a small one for module 9, with one deliberate mistake at the end:

```dockerfile
FROM eclipse-temurin:25-jre
COPY target/module-09-catalog-0.1.0-SNAPSHOT.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
MAINTAINER someone
```

Open it and two diagnostics appear, both from hadolint. Line 2 gets a warning: *`COPY` to a relative destination without `WORKDIR` set.* Line 5 gets an error: *MAINTAINER is deprecated*. The fixes are the usual ones: set a `WORKDIR` before the `COPY`, and use a `LABEL` instead of `MAINTAINER`. hadolint's README lists every rule with its reason. Diagnostics, jumping and `<leader>xx` work as in Part 3.

## Validate a Compose file

A Compose file that starts PostgreSQL for local development, with a typo:

```yaml
services:
  db:
    image: postgres:17
    environment:
      POSTGRES_PASSWORD: shop
    port:
      - "5432:5432"
```

yamlls recognises `compose.yaml` from its file name and checks it against the Compose schema. Line 6 gets an error: *Property port is not allowed.* The key is `ports`, plural.

The `lang.docker` extra also lists a separate Compose language server. In our test it did not attach to `compose.yaml`, because Neovim gave the file the plain `yaml` filetype. The schema check from yamlls was enough to catch the mistake.

## Teach yamlls about Kubernetes

Kubernetes manifests are YAML too, but there is no file name that marks them, so yamlls cannot guess. You tell it which files are Kubernetes with a glob, in a small plugin file of your own:

```lua
{
  "neovim/nvim-lspconfig",
  opts = { servers = { yamlls = { settings = { yaml = {
    schemas = { kubernetes = { "k8s/**/*.yaml", "k8s/**/*.yml" } },
  } } } } },
}
```

[nvim-spring-ide: lua/plugins/kubernetes-yaml.lua](https://github.com/mnafshin/nvim-spring-ide/blob/main/lua/plugins/kubernetes-yaml.lua)

Every YAML file under a `k8s/` folder now gets the Kubernetes schema. Change the glob to match your project. Here is a Deployment with a wrong type:

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: shop
spec:
  replicas: "two"
```

yamlls marks `replicas` with *Incorrect type. Expected "integer".* Hover over it with `K` and you get the field's documentation: the number of desired pods, which defaults to 1.

## Keep Java tools out of YAML

One detail from Part 4 matters here. If the Spring Boot plugin loaded for every YAML file, opening a Kubernetes manifest would also start jdtls. The ready-made configuration loads it only for `application*.yml`, so in our test a manifest under `k8s/` started only yamlls.

## What this setup does not do

This setup edits files. It does not build images, start containers, read container logs or talk to a cluster. The test machine had neither the Docker CLI nor `kubectl`, so we tested none of that. Plugins exist that wrap `kubectl` inside Neovim, and a terminal split with `<leader>ft` always works for `docker compose up` or `kubectl apply`, but neither is part of this series' tested setup.

Compared with IntelliJ IDEA Ultimate, which has a Services tool window for containers and a Kubernetes plugin that browses a cluster, the gap is real.

## Recap

- `lang.docker` adds `dockerls` and `hadolint` for Dockerfiles; `lang.yaml` adds `yamlls`.
- yamlls validates `compose.yaml` against the Compose schema by file name.
- Map Kubernetes files to the `kubernetes` schema with a glob such as `k8s/**/*.yaml`; then you get type errors, hover docs and completion.
- Load the Spring Boot plugin only for `application*.yml` so manifests don't start jdtls.
- Running containers, logs and `kubectl` are outside this setup.

**Series: Neovim as a Java IDE.** Previous: [A database tool in Neovim with vim-dadbod](/devtools/11-database-tool-dadbod/) · Next: [Copy and paste between Neovim and the system clipboard](/devtools/13-clipboard/)

## Sources

Official documentation and well-known tutorials read while writing this article. The wording here is our own.

- [LazyVim: lang.docker extra](https://www.lazyvim.org/extras/lang/docker)
- [LazyVim: lang.yaml extra](https://www.lazyvim.org/extras/lang/yaml)
- [yaml-language-server README (schemas, Kubernetes)](https://github.com/redhat-developer/yaml-language-server)
- [dockerfile-language-server README](https://github.com/rcjsuen/dockerfile-language-server)
- [hadolint README and rules](https://github.com/hadolint/hadolint)
- [Compose file reference: services](https://docs.docker.com/reference/compose-file/services/)
- [Kubernetes: Deployments](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)
- [nvim-lspconfig: yamlls (schemas and the Kubernetes special case)](https://github.com/neovim/nvim-lspconfig/blob/master/lsp/yamlls.lua)
- [cylab.be: Neovim for YAML](https://cylab.be/blog/415/neovim-for-yaml)
- [Kokil: Neovim Setup for DevOps Engineers](https://kokil.com.np/blog/neovim-setup-for-devops-engineers)
- [blak.nvim: Docker extra (Compose filetype detection)](https://getblak.dev/extras/lang/docker/)
