#2109·kompose

[BUG] kompose convert panics on a volume that is only a name and an access mode

Author: arpitjain099Created Aug 23, 2026Updated Aug 23, 2026
Labelskind/bug

Expected Behavior

kompose convert should report a malformed volume entry as an error and exit, the way it already does for other bad volume strings.

Actual Behavior

It panics with index out of range [-1] and prints a Go stack trace. Exit code is 2.

panic: runtime error: index out of range [-1]

goroutine 1 [running]:
github.com/kubernetes/kompose/pkg/transformer.parseVolume({0x398b7b3b6350, 0x8})
	/kompose/pkg/transformer/utils.go:112 +0x4bc
github.com/kubernetes/kompose/pkg/transformer.ParseVolume({0x398b7b3b6350, 0x8})
	/kompose/pkg/transformer/utils.go:72 +0x60
github.com/kubernetes/kompose/pkg/loader/compose.ParseVols({0x398b7b5a01a0?, 0x1, 0x0?}, {0x398b7b3b63b0, 0x3})
	/kompose/pkg/loader/compose/compose.go:928 +0xf8
github.com/kubernetes/kompose/pkg/loader/compose.retrieveVolume(...)
	/kompose/pkg/loader/compose/compose.go:903 +0xc8
github.com/kubernetes/kompose/pkg/loader/compose.handleVolume(...)
	/kompose/pkg/loader/compose/compose.go:837 +0xb8
github.com/kubernetes/kompose/pkg/loader/compose.dockerComposeToKomposeMapping(...)
	/kompose/pkg/loader/compose/compose.go:609 +0xb94
github.com/kubernetes/kompose/pkg/app.Convert(...)
	/kompose/pkg/app/app.go:221 +0xbc

Steps To Reproduce

  1. Save the compose file below.
  2. Run kompose convert --stdout.
  3. It panics instead of printing an error.

myvol:rw, myvol:z and myvol:Z do the same thing. Well-formed entries such as myvol:/data:ro and /host:/data:ro are unaffected.

Kompose Version

1.38.0 (HEAD)

built from main at c2dd9614fd5026b8f6cb95d61bba802626088b13.

Docker-Compose file

yaml
services:
  web:
    image: nginx
    volumes:
      - "myvol:ro"

volumes:
  myvol:

Anything else?

parseVolume in pkg/transformer/utils.go takes the volume name off the front of the split list and a trailing rw/ro/z/Z off the back, then reads the container path with volumeStrings[len(volumeStrings)-1]. For myvol:ro those two steps consume the whole list, so the index goes to -1.

The entry is not usable in the first place. Compose reads the second field as the container target rather than as an access mode, and the engine then rejects it:

Error response from daemon: invalid volume specification: 'repro-vol_myvol:ro:rw': invalid mount config for type "volume": invalid mount path: 'ro' mount path must be absolute

So an error is the right outcome here, and parseVolume already returns invalid volume format for a bare ro via the same length check one branch earlier. #2108 adds the equivalent check after the access mode is stripped.