mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-04 04:31:28 +00:00
DRY up valid container name pattern usage
This commit is contained in:
+5
-4
@@ -31,8 +31,9 @@ import (
|
||||
const MaxImageDepth = 127
|
||||
|
||||
var (
|
||||
defaultDns = []string{"8.8.8.8", "8.8.4.4"}
|
||||
validContainerName = regexp.MustCompile(`^/?[a-zA-Z0-9_.-]+$`)
|
||||
defaultDns = []string{"8.8.8.8", "8.8.4.4"}
|
||||
validContainerNameChars = `[a-zA-Z0-9_.-]`
|
||||
validContainerNamePattern = regexp.MustCompile(`^/?` + validContainerNameChars + `+$`)
|
||||
)
|
||||
|
||||
type Capabilities struct {
|
||||
@@ -425,8 +426,8 @@ func (runtime *Runtime) Create(config *Config, name string) (*Container, []strin
|
||||
name = utils.TruncateID(id)
|
||||
}
|
||||
} else {
|
||||
if !validContainerName.MatchString(name) {
|
||||
return nil, nil, fmt.Errorf("Invalid container name (%s), only [a-zA-Z0-9_-] are allowed", name)
|
||||
if !validContainerNamePattern.MatchString(name) {
|
||||
return nil, nil, fmt.Errorf("Invalid container name (%s), only %s are allowed", name, validContainerNameChars)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user