T
ToolPrime

Regex for Docker Image Tag

Validates Docker image references with optional registry, namespace, and tag.

Pattern

/^([a-z0-9]+([._-][a-z0-9]+)*(\/[a-z0-9]+([._-][a-z0-9]+)*)*)(:([a-zA-Z0-9][a-zA-Z0-9._-]{0,127}))?$/

Live Tester

Enter a string to test

Examples

nginx:latest
myregistry.io/myapp:v1.2.3
library/ubuntu:22.04
NGINX:latest
:latest
image:

Pattern Breakdown

^([a-z0-9]+([._-][a-z0-9]+)*) — image name segment (lowercase)

(\/...)* — optional additional path segments

(:([a-zA-Z0-9]...))? — optional colon + tag (up to 128 chars)

Code Snippets

Javascript

const regex = /^([a-z0-9]+([._-][a-z0-9]+)*(\/[a-z0-9]+([._-][a-z0-9]+)*)*)(:([a-zA-Z0-9][a-zA-Z0-9._-]{0,127}))?$/;
regex.test("nginx:latest"); // true

Python

import re
pattern = r"^([a-z0-9]+([._-][a-z0-9]+)*(/[a-z0-9]+([._-][a-z0-9]+)*)*)(:([a-zA-Z0-9][a-zA-Z0-9._-]{0,127}))?$"
bool(re.match(pattern, "nginx:latest"))  # True

Php

$pattern = '/^([a-z0-9]+([._-][a-z0-9]+)*(\/[a-z0-9]+([._-][a-z0-9]+)*)*)(:([a-zA-Z0-9][a-zA-Z0-9._-]{0,127}))?$/';
preg_match($pattern, "nginx:latest"); // 1

Related Patterns

Frequently Asked Questions

What is the regex for Docker Image Tag?
The regex pattern for Docker Image Tag is /^([a-z0-9]+([._-][a-z0-9]+)*(\/[a-z0-9]+([._-][a-z0-9]+)*)*)(:([a-zA-Z0-9][a-zA-Z0-9._-]{0,127}))?$/. Validates Docker image references with optional registry, namespace, and tag.
How do I use the Docker Image Tag regex in JavaScript?
In JavaScript you create the pattern with a regex literal or the RegExp constructor and call .test() to check a string against it. A ready-to-copy example is shown in the Code Snippets section above, alongside Python and PHP versions.
What does the Docker Image Tag pattern match?
It matches strings like nginx:latest; it rejects strings like NGINX:latest. See the Examples section above for the full list of matching and non-matching cases.

Related Tools