Dockerfile EXPOSE: document the listening port
Read the recipe
FROM busybox:1.37EXPOSE 8080/tcpCMD ["echo", "metadata-only"]This recipe deliberately has no web server. The image advertises TCP port 8080 even though its command only prints a message. Inspect the image configuration instead of attempting an HTTP request. The TCP protocol is the default when omitted; UDP can be declared separately. Runtime -p creates a specified host mapping and -P can publish exposed ports automatically; neither is used in this offline lab. EXPOSE is metadata even when the program exits immediately. Do not use -P to test it: that would create host publications outside this lab’s scope.
Try it in a local lab
Manual lab only, not an interactive ByteMind execution. Use an approved disposable offline Linux VM, verified local Engine and Buildx docker driver. Check docker context show, docker version, docker buildx version and docker buildx ls. Confirm the local context/builder, reviewed preloaded busybox:1.37 with root default, no entrypoint, and required applets. Record actual digest/platform and use reviewed digest for repeatability. No network egress; --network none is not a complete builder egress control. Verify every bm-v08 image tag and container name in the commands is unused. Use synthetic data only. Run commands individually and stop on unexpected failure; remove only resources created by this lab after ownership checks. If cleanup cannot be confirmed, retire the disposable VM. Expected results are predictions, not observed output. Before contacting any Engine, resolve DOCKER_HOST, DOCKER_CONTEXT and CLI context overrides; also check BUILDX_BUILDER and any builder override. Confirm that the actual builder used by docker build is the approved local docker driver. Review the base configuration for inherited triggers, volumes, health checks, user, shell and required applets; stop if assumptions differ. Make a private working copy containing only the supplied synthetic files. An approved digest may require registry metadata resolution even when layers are present locally; if the offline builder cannot resolve it, stop and record the limitation. Record the actual base image ID, platform, builder version and output image ID; never substitute an unknown digest. Do not retry by enabling egress. Apply owner-approved time and resource budgets and retire the VM if cleanup is uncertain.
Open lab-fixtures/dockerfile-configuration/02-expose/ from the extracted archive. Save the complete recipe and any additional files below in that directory.
docker build --load --network none -t bm-v08-expose:lab .docker run --rm --pull=never --network none bm-v08-expose:labdocker image inspect --format '{{json .Config.ExposedPorts}}' bm-v08-expose:labExpect metadata-only from the run and an exposed-port map containing 8080/tcp from inspect. There is no listening service in this example and no host mapping.
Confirm the tag belongs to this lab and no container depends on it. Remove it without forcing deletion. Build cache may remain until VM disposal. Record output and exit status before removing the exact lab tag. Recheck the tag against the recorded output image ID; a tag may have been reassigned.
Common mistake
Adding EXPOSE does not make a service accessible or restrict access to other ports. The process must listen, and publication/network policy must be configured independently.
Manual practice
Explain why an image can advertise port 8080 even if its program exits immediately. Describe the three independent checks for a real server: process listener, mapping and network policy.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Dockerfile EXPOSE: document the listening port — Knowledge check
Apply the configuration concept to a new image or container scenario.
What does EXPOSE 8080/tcp set?
What is missing for a server to respond?
Does this recipe publish a host port?