Need help?

Our experts will login to your server within 30 minutes to fix urgent issues.

Customer support or server support, make your own solution using our support configuration wizard.

How to expose docker ports to make your containers externally accessible

How to expose docker ports to make your containers externally accessible

Virtualization using Docker containers has gained popularity in application hosting, owing to its light-weight design and fast-deployment features.

Docker architecture is in such a way that the containers can connect to the outside world by default. But you cannot access the container directly from outside.

While disabling external access is a good security measure, there maybe many instances where you need to access the container data from outside, such as application testing, website hosting and so on.

Setup and manage your Docker system



To allow external access to Docker containers, you would have to expose their ports by mapping a container’s port to an external port in the host. Today we’ll see how to expose docker ports to make them accessible from the internet.


What is port binding in Docker?

Suppose you want to run an NginX web server application in your Docker container. You can install the nginx image and start a container but you cannot directly access it from outside network.

Docker containers have an internal network and each container is associated with an IP address that can be accessed from the Docker host machine.

Being internal IP, this IP cannot be used to access the containers from external network. But the Docker host machine’s main IP is accessible from outside.

For a webserver application, you’d obviously need to enable user access to it from the external network. So, the solution we use is to bind the internal port 80 of the Docker container to a port on the host machine, say 9000.

With this port forwarding or port binding feature, users can access the webserver at container port 80 using the host machine port 9000. Users may not even notice this backend forwarding while accessing the webserver.

[ Are your spending too much time managing your Docker containers? Our Docker experts take care of your infrastructure and ensure its smooth functioning. ]


How to expose docker ports during container creation

Exposing Docker ports can be done using the ‘-p’ option with ‘docker run’ command to bind the port when launching the container:

docker run -d -p 9090:80 -t nginx

This command will create a container with the image ‘nginx’ and bind the container’s port 80 to the host machine’s port 9090.

You can verify this using ‘docker ps‘ command:


docker port expose - create container

Expose Docker port during container creation


To see the port bindings of a specific container, use the ‘docker inspect [container-id]’ command:


docker port expose - binding ports

Port bindings of container


Once the port exposure is complete and the container is up and running, the internal port 80 of the container can be accessed using the host machine IP and port, at http://host-ip-address:9090/ .

[ Running a Docker infrastructure doesn’t have to be hard, or costly. Get world class Docker management services at affordable pricing. ]


Do you provide Docker hosting services?

Wish you had more time to focus on your business? Let us help you.

Our engineers will assist you to setup, monitor and manage your Docker infrastructure 24/7.


Submit a Comment

Your email address will not be published. Required fields are marked *

Bobcares is a server management company that helps businesses deliver uninterrupted and secure online services. Our engineers manage close to 51,500 servers that include virtualized servers, cloud infrastructure, physical server clusters, and more.