Docker container connection 1. Network port mapping We create a container for a python application
We create a container using the -P parameter and use docker ps to see that port 5000 is bound to host port 32768 We can also use the -p flag to specify that the container port should be bound to the host port. The difference between the two methods is: -P: The internal port of the container is randomly mapped to the high port of the host. -p: Bind the container's internal port to the specified host port. …… ...
In addition, we can specify the network address bound to the container, such as binding 127.0.0.1
In this way, we can access port 5000 of the container by accessing 127.0.0.1:5001 By default, containers are bound to TCP ports. If you want to bind to UDP ports, you can add /udp after the port.
The docker port <images id> [port] command allows us to quickly view the port binding status
Now we shut down all other containers and start a new nginx container
We forward the container's port 80 to the local port 5000 and then access it externally You can see that we can access it successfully, indicating that the port is forwarded. 2. Docker container connection Port mapping is not the only way to connect Docker to another container. Docker has a connection system that allows multiple containers to be connected together and share connection information. A docker connection creates a parent-child relationship where the parent container can see the child container's information. 3. Container naming When we create a container, Docker will automatically name it. But we can also use the --name flag to name the container
Additional knowledge: How to view which ports are open inside a Docker container You don't need to enter the container bash, just enter the docker port container id in the Linux command line to view it The above article about how to connect a container through a port in Docker is all I have to share with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: JS realizes special effects of web page navigation bar
>>: MySQL data archiving tool mysql_archiver detailed explanation
1. Go to Vim's official website to download t...
The specific code of JavaScript date effects is f...
Table of contents 1. The direction of this in the...
Table of contents Overview 1. Path module 2. Unti...
Jellyka BeesAntique Handwriting [ank]* Jellyka Cut...
Without going into details, let's go straight...
System environment: Redis version: 6.0.8 Docker v...
Problem description: The user has a requirement t...
Table of contents 1. Download steps 2. Configure ...
Achieve results html <div class="containe...
1. Configuration By default, the first two are no...
Preface In many MySQL test scenarios, some test d...
Usually the goal of building a website is to have...
Table of contents Preface Browser compiled versio...
Failure Scenario When calling JDBC to insert emoj...