Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Implementation of Docker Port Mapping

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

When the docker container starts, if you do not specify the port mapping parameters, the network applications and services in the container cannot be accessed through the network outside the container.

It can also be configured using the EXPOSE directive in the Dockerfile file.

Port mapping can be implemented using-p,-P:

-p specifies the port to be mapped, and only one container can be bound to a specified port-P randomly maps the open network port inside the container to one port of the host

Formats supported by port mapping:

Ip:hostport:containerport # specify ip, specify host port, specify container portip::containerport # specify ip, not specify host port (random), specify container porthostport:containerport # not specify ip, specify host port, specify container port

There are five ways to map ports:

First, all ports exposed by the container are randomly mapped to the host.

For example: (not recommended)

Docker run-P-it ubuntu / bin/bash

Second, randomly map the specified port of the container to a port of the host.

For example:

Docker run-P 80-it ubuntu / bin/bash

The above instruction will randomly map port 80 of the container to a port of the host.

Third, map the specified port of the container to a port of the host.

For example:

Docker run-p 8000 80-it ubuntu / bin/bash

The above instruction maps port 80 of the container to port 8000 of the host.

4. Randomly map the container ip and port to the host.

Docker run-P 192.168.0.100 Freund 80-it ubuntu / bin/bash

The above instruction will randomly map the ip192.168.0.100 and port 80 of the container to a port of the host.

5. Map the container ip and port to the host.

Docker run-p 192.168.0.100 bin/bash 8000 it ubuntu 80

The above instruction maps the container's ip192.168.0.100 and port 80 to the host's port 8000.

Example:

# Mapping port 80 of nginx to port 800 of host docker run-d-it-p 800 it 80 nginx

View mapped port configuration

Docker port container_ID # Container ID# result output 80/tcp-> 0.0.0.0 80/tcp 800

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report