How can I expose more than 1 port with Docker?

Better Stack Team
Updated on April 7, 2023

You can expose more than one port in a Docker container by using the -p option when starting the container. The -p option maps a port on the host machine to a port in the container. You can specify multiple port mappings by using multiple -p options.

Here's an example of how to expose two ports, port 80 and port 443:

 
docker run -d -p 80:80 -p 443:443 my-image

In this example, the -p 80:80 option maps port 80 on the host machine to port 80 in the container, and the -p 443:443 option maps port 443 on the host machine to port 443 in the container.

Note that when you expose multiple ports in a Docker container, the container must be configured to listen on those ports.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack