Files
moby/daemon/rename.go
Sebastiaan van Stijn a5c0f152a7 daemon: improve validation for container rename
Improve validation for empty name; while the daemon already handled empty
strings, it didn't account for the "canonical" name with "/" prefix, for
which it would produce an obscure error:

    Error response from daemon: Error when allocating new name: Invalid container name (/ ), only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed

Before this change:

    curl -XPOST --unix-socket /var/run/docker.sock 'http://localhost/v1.51/containers/old/rename?name='
    {"message":"Neither old nor new names may be empty"}

    curl -XPOST --unix-socket /var/run/docker.sock 'http://localhost/v1.51/containers/old/rename?name=/'
    {"message":"Error when allocating new name: Invalid container name (/), only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed"}

    curl -XPOST --unix-socket /var/run/docker.sock 'http://localhost/v1.51/containers/old/rename?name=/hello'
    # OK

A check was added in the client as well for situations where an older daemon
is used; the same code currently was implemented in the CLI.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-29 18:42:36 +01:00

4.5 KiB