How to check if docker mapping is successful

WBOY
Release: 2022-06-22 16:11:08
Original
7360 people have browsed it

Docker has two methods to check whether the mapping is successful: 1. Use the "docker ps" command to check. If "6379/tcp" appears, it means that the host has not opened port mapping with the virtual machine; 2. Use " docker port name" command. If there is no result, it means that the specified port mapping failed.

How to check if docker mapping is successful

The operating environment of this tutorial: linux7.3 system, docker version 19.03, Dell G3 computer.

How docker check whether the mapping is successful

Why do we need port mapping?

When starting a container, if the port mapping between the host machine and the virtual machine is not configured, external programs will not be able to access the virtual machine because there is no port.

What are the instructions for port mapping?

docker command: docker run -p ip:hostport:containerport redis

Using the -p parameter will allocate the host port to be mapped to the virtual machine.

ip represents the ip address of the host.

hostport represents the port of the host.

containerport represents the port of the virtual machine.

There are three supported formats:

  • ip:hostport:containerport: mapping the specified port of the specified address to the specified port of the virtual machine (not commonly used)

For example: 127.0.0.1:3306:3306, map the 3306 port of the local machine to the 3306 port of the virtual machine.

  • ip::containerport: Map any port at the specified address to the specified port of the virtual machine. (Not commonly used)

For example: 127.0.0.1::3306, map the 3306 port of the local machine to the 3306 port of the virtual machine.

  • hostport:containerport: Map the specified port of the local machine to the specified port of the virtual machine. (Commonly used)

For example: 3306:3306, map the 3306 port of the local machine to the 3306 port of the virtual machine.

How to check whether the mapping is successful?

1. Use the docker ps command to check

How to check if docker mapping is successful

How to check whether the Docker port mapping is successful

The occurrence of 6379/tcp means that the host does not open port mapping with the virtual machine.

The appearance of 0.0.0.0:3306->3306/tcp indicates that the 3306 port of the host is mapped to the 3306 port of the virtual machine.

2. You can also use docker port name to check the port mapping situation.

How to check if docker mapping is successful

How to check whether the Docker port mapping is successful

It means that the 3306 port of the virtual machine is mapped to the 3306 port of the host.

If there is no reply, it means that the port mapping failed.

Recommended learning: "docker video tutorial"

The above is the detailed content of How to check if docker mapping is successful. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template