English

Developer tools · Docker run to Docker compose converter

Docker port mapping syntax: converting -p 8080:80/udp to Compose ports

· How it works

docker compose ports

Abstract diagram illustrating docker port mapping syntax: converting -p 8080:80/udp to compose ports
Original ToolAcre vector illustration

The -p flag packs host IP, host port, container port and protocol into one string. This post breaks the string down, shows the Compose short and long syntax, and explains the YAML quoting trap.

Port 22 became 1342 — a Compose file ported by hand exposes something nobody asked for

Port 22 became 1342 — a Compose file ported by hand exposes something nobody asked for. Evidence: Every -p value is retained under ports as short syntax. Reproduce port publication with disposable literals. Pair each source occurrence with ports and expose; reserve binding and protocol for destination review.

The ports incident also reveals that A separate ports incident boundary is that no long-form target or published mapping is produced. Evidence: no long-form target or published mapping is produced. This port publication constraint is a stopping point. Inspect ports and expose without manufacturing behavior, then document a host check for binding and protocol.

Anatomy of -p — [ip:]hostPort:containerPort[/protocol], with ranges and the host-port-omitted form that picks a random port

Anatomy of -p — [ip:]hostPort:containerPort[/protocol], with ranges and the host-port-omitted form that picks a random port. Evidence: spaced, equals, attached, repeated, ranged, UDP, IPv4 and IPv6 spellings are tested. Trace port publication tokens into ports and expose. Separate ordered values from last-value fields; binding and protocol is outside collection.

A related ports mechanism boundary is that A separate ports grammar boundary is that three publish options become three ordered list entries. Evidence: three publish options become three ordered list entries. Use this port publication fact to predict one member or scalar in ports and expose. Check warnings before deciding anything about binding and protocol.

Compose short syntax — the same string as a list item, and why it should always be quoted

Compose short syntax — the same string as a list item, and why it should always be quoted. Evidence: colon-heavy port strings are quoted by the YAML writer. Judge port publication serialization from its model. Quoting in ports and expose protects types but gives no operational proof for binding and protocol.

The second ports serialization observation is A separate ports output boundary is that --expose writes expose and never substitutes for publishing. Evidence: --expose writes expose and never substitutes for publishing. This port publication output separates settings from unavailable context. Keep ports and expose reviewable and check binding and protocol independently.

The converter emits only quoted short-form ports; it does not generate the long mapping form

Compose long syntax — target, published, protocol, host_ip and mode as explicit keys. Evidence: no long-form target or published mapping is produced; The converter emits only quoted short-form ports; it does not generate the long mapping form. Stop at the port publication exception instead of guessing. Any addition near ports and expose needs a deployment-specific reason tied to binding and protocol.

Another ports exception constraint is that for this ports section keep the original for this ports section command and warnings for this ports section beside this candidate file. Evidence: the repository gives no broader runtime or historical proof. Keep the original port publication command beside warnings. The comparison shows what ports and expose contains and which binding and protocol decision remains manual.

Worked example: three -p flags to a ports list — TCP and UDP on the same port, a localhost-only binding and a port range

Worked example: three -p flags to a ports list — TCP and UDP on the same port, a localhost-only binding and a port range. Build the port publication example from synthetic names. Make every ports and expose item traceable without exposing production binding and protocol details.

The same ports example sample demonstrates that A separate ports example boundary is that the result exposes each preserved binding for inspection. Evidence: the result exposes each preserved binding for inspection. The paired port publication fact should be visible in ports and expose. Record that line and avoid assumptions about binding and protocol.

expose versus ports — why -p publishes to the host while expose only documents a port between services

expose versus ports — why -p publishes to the host while expose only documents a port between services. Translate the port publication consequence into one observable ports and expose difference. Docker owns the later binding and protocol verdict.

The ports consequence implementation also shows A separate ports effect boundary is that Every -p value is retained under ports as short syntax. Split port publication responsibilities: conversion writes ports and expose, the repository removes secrets, and operators validate binding and protocol.

What this does not cover — network_mode: host, where ports are ignored, and reverse proxies that make publishing unnecessary

What this does not cover — network_mode: host, where ports are ignored, and reverse proxies that make publishing unnecessary. Evidence: host mode keeps ports for reference and warns that they have no effect. Limit port publication scope to ports and expose branches shown here. Neighboring forms and defaults cannot answer binding and protocol questions.

One more ports scope limit follows from A separate ports limit boundary is that spaced, equals, attached, repeated, ranged, UDP, IPv4 and IPv6 spellings are tested. Treat this port publication boundary as an exclusion. Prefer accurate ports and expose over guesses about binding and protocol.

Takeaway: quote your ports and know each segment — and the converter shows how each -p becomes a ports entry

Takeaway: quote your ports and know each segment — and the converter shows how each -p becomes a ports entry. Audit port publication as source option, model field, ports and expose line and warning. Remove secrets before checking binding and protocol.

Finally, the ports takeaway source confirms A separate ports decision boundary is that colon-heavy port strings are quoted by the YAML writer. Close port publication narrowly: ports and expose is a candidate; binding and protocol and shell equivalence are not guarantees.