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

11 Linux KDE applications you didn't know about

KDE Abbreviation for Kool Desktop Environment. A ...

Problems and solutions for installing Docker on Alibaba Cloud

question When installing Docker using Alibaba Clo...

How to configure wordpress with nginx

Before, I had built WordPress myself, but at that...

A brief discussion on HTML doctype and encoding

DOCTYPE Doctype is used to tell the browser which...

Tutorial on installing phpMyAdmin under Linux centos7

yum install httpd php mariadb-server –y Record so...

The use of v-model in vue3 components and in-depth explanation

Table of contents Use two-way binding data in v-m...

Summary of Commonly Used MySQL Commands in Linux Operating System

Here are some common MySQL commands for you: -- S...

10 excellent Web UI libraries/frameworks

1. IT Mill Toolkit IT Mill Toolkit is an open sou...

A brief introduction to React

Table of contents 1. CDN introduction 1.1 react (...

Detailed graphic tutorial on how to enable remote secure access with Docker

1. Edit the docker.service file vi /usr/lib/syste...

Tutorial on how to create a comment box with emoticons using HTML and CSS

HTML comment box with emoticons. The emoticons ar...

Summary of the Differences between SQL and NoSQL

Main differences: 1. Type SQL databases are prima...