Skip to content
Latchkey

Dockerfile EXPOSE "invalid containerPort" in CI

The EXPOSE instruction was given a value that is not a valid port. A letter in the number, an empty value from an unexpanded ARG, or a stray character all trigger "Invalid containerPort".

What this error means

docker build fails with "invalid containerPort: 8O80" or a similar value while processing the EXPOSE instruction.

docker build
invalid containerPort: 8O80

Common causes

A typo in the port number

A letter substituted for a digit (a capital O for a zero) makes the value non-numeric.

An unexpanded build argument

An ARG or ENV used as the port resolved to empty or a non-number, so EXPOSE receives an invalid value.

How to fix it

Use a valid numeric port

Give EXPOSE a plain port number, optionally with a protocol.

Dockerfile
EXPOSE 8080
EXPOSE 8080/tcp

Verify any variable resolves to a number

  1. Check that an ARG or ENV used as the port is set to a number.
  2. Print the value during build if EXPOSE keeps rejecting it.
  3. Avoid letters and stray characters in the port.

How to prevent it

  • Use plain numeric ports in EXPOSE.
  • Ensure variables used as ports resolve to numbers.
  • Watch for O/0 and l/1 typos in port values.

Frequently asked questions

What causes ""invalid containerPort""?
A letter substituted for a digit (a capital O for a zero) makes the value non-numeric.
How do I fix "invalid containerPort"?
Give EXPOSE a plain port number, optionally with a protocol.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card