O'Reilly logo

Docker and Kubernetes for Java Developers by Jaroslaw Krochmalski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

EXPOSE

The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. We have already mentioned the EXPOSE instruction in Chapter 2, Networking and Persistent Storage. As you will remember, EXPOSE in a Dockerfile is the equivalent to the --expose command-line option. Docker uses the EXPOSE command followed by a port number to allow incoming traffic to the container. We already know that EXPOSE does not make the ports of the container automatically accessible on the host. To do that, you must use either the -p flag to publish a range of ports or the -P flag to publish all of the exposed ports at once.

Let's get back to our Dockerfile and expose a port:

FROM jeanblanchard/java:8COPY target/rest-example-0.1.0.jar ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required