Detailed explanation of Docker container network port configuration process

Detailed explanation of Docker container network port configuration process

Exposing network ports

In fact, there are two parameters in Docker that involve exposing network ports, namely -p and -P. The following will introduce them separately.

-P

With -P, Docker will randomly assign an unused port to the application on the host and map it to the open port in the container.
For example, as follows:

As you can see, Docker assigns a random port 32768 to the application, which can be used to access the container.
nginx(http://lcalhost:32768).

-p

The -p parameter has several different uses:

hostPort:containerPort

This usage is to bind the host port and the container port, as follows:


The above command means mapping port 80 of the host machine to port 80 of the container. The first port 80 is port 80 of the host machine, and the second port 80 is port 80 of the container.

ip:hostPort:containerPort

This method maps the port of the specified IP address to the port of the container. as follows:


Map port 80 of the 192.168.0.195 address to port 80 of the container.

ip::containerPort

This method maps a random port of a specified IP address to an open port of a container, as follows

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to modify the port mapping of a running Docker container
  • How to dynamically modify container port mapping in Docker
  • Perfect solution to the problem of not being able to access the port of the docker container under Windows 10
  • Docker connects to a container through a port
  • Docker dynamically exposes ports to containers
  • Solution to the Docker container being unable to access the host port
  • Troubleshooting process for Docker container suddenly failing to connect after port mapping
  • Solution for multiple Docker containers not having the same port number

<<:  Detailed process of implementing the 2048 mini game in WeChat applet

>>:  MySQL query sorting and paging related

Recommend

Solution to the docker command exception "permission denied"

In Linux system, newly install docker and enter t...

W3C Tutorial (16): Other W3C Activities

This section provides an overview of some other i...

Analysis of Context application scenarios in React

Context definition and purpose Context provides a...

Delegating Privileges in Linux Using Sudo

Introduction to sudo authority delegation su swit...

Summary of some small issues about MySQL auto-increment ID

The following questions are all based on the Inno...

Tutorial on installing and configuring MySql5.7 in Alibaba Cloud ECS centos6.8

The default MySQL version under the Alibaba Cloud...

Call and execute host docker operations in docker container

First of all, this post is dedicated to Docker no...

Detailed steps for installing Harbor, a private Docker repository

The installation of Harbor is pretty simple, but ...

The most detailed method to install docker on CentOS 8

Install Docker on CentOS 8 Official documentation...

How to use Web front-end vector icons

Preface When writing front-end pages, we often us...

5 Commands to Use the Calculator in Linux Command Line

Hello everyone, I am Liang Xu. When using Linux, ...

A record of the pitfalls of the WeChat applet component life cycle

The component lifecycle is usually where our busi...

The use and difference between JavaScript pseudo-array and array

Pseudo-arrays and arrays In JavaScript, except fo...

Analysis and solution of MySQL connection throwing Authentication Failed error

[Problem description] On the application side, th...