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

How to open the port of docker container

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

Share

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

This article shows you how to start the docker container, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

How do I start a docker container? There are usually two ways for docker to add mapped ports to a running container.

Method one

Docker commit docker run-p containerid

Use the above command to create a new image file, and the run-p parameter opens the new port, which is not convenient to use in practice.

Method two

Modify the iptables rules on the host (host) to open the response port of the container; refer to the commands on the network

Iptables-t nat-A DOCKER-p tcp-dport 8080-j DNAT-- to-destination 172.17.0.2 DOCKER 8080

When we create a nginx image and start nginx, we can only access the nginx URL in the inner area of the container. Therefore, in order to be accessible outside the container, the port needs to be exposed, and the port inside the container needs to be mapped out.

There are four forms of docker container exposure ports:

1.-p

Maps the specified container port to a random port of all host addresses

2.-p:

Map the container port to the specified host port

3.-p::

Map the container port to the random port of the host-specified ip

4.-p:

Map the container port to the specified port of the specified host ip

The above is how to start the docker container. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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