In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
External access
Random mapping port
Using the-P flag, Docker randomly maps a port of 49000-49900 to the open network port of the internal container docker run-d-P training/webapp python app.pydocker ps-l # to display the recently created container docker logs-f web # to view application information
Map all interface addresses
Docker run-d-p 5000 training/webapp python app.py
Map to the specified port of the specified address
Docker run-d-p 127.0.0.1 Fren 5000 training/webapp python app.py
Map to any port at the specified address
Docker run-d-p 127.0.0.1 Virgo 5000 training/webapp python app.py
Specify udp port
Docker run-d-p 127.0.0.1:5000:5000/udp training/webapp python app.py
View mapped port configuration
Dokcer port web 5000
Create a new docker network
Docker network create-d bridge my-net
Run the container to connect to the new my-net network
Docker run-it-rm-name busybox1-network my-net busybox shdocker run-it-rm-name busybox2-network my-net busybox sh
View container information
Ping tests whether containers are interconnected in docker container ls containers
Docker Compose is recommended for interconnection of multiple containers
After the configuration of DNS host DNS information is updated, the DNS configuration of all Docker containers is updated immediately through / etc/resolv.conf
Configure DNS for all containers
Vim / etc/docker/daemon.json adds {'dns': ["114.114.114.114", "8.8.8.8"]} docker run-it-- rm ubuntu:17.10 cat / etc/resolv.conf
Container interconnection
The connection system of the container is another way to interact with the application in the container in addition to the port mapping.
It creates a tunnel between the source and the receiving container, and the receiving container can see the information specified by the source container.
Custom container name
The connection system is executed according to the name of the container, so you need to customize a container name that is relatively simple and easy to distinguish.
Custom naming uses the-- name parameter, which was encountered in previous articles:
Docker run-d-p-- name db mysql
The container must be named uniquely.
When executing docker run, if you add the-- rm parameter, the container is deleted immediately upon termination, but cannot be used with the-d parameter.
Container interconnection
Use the-- link parameter to allow containers to establish secure connections for interaction.
Here is an example:
First create a container for the database:
Docker run-d-name db training/postgres
Then create the web container:
Docker run-d-P-- name web-- link db:db training/webapp python app.py
At this point, the db container and the web container add your interconnection.
-- link parameter:-- link name:alias,name is the name of the container to be connected, and alias is the alias for this connection.
You can use docker ps to view container information, where the names column can see the status of the interconnection.
Docker establishes a secure tunnel between two interconnected containers, eliminating the need to map their ports to the host host and avoiding port exposure.
Docker exposes connection information in two ways:
Environment variable update / etc/hosts file
Use the env command to view the environment variables of the web container just now:
Docker run-rm-name web2-link db:db training/webapp env...
The environment variable that begins with DB_ is used by the web container to connect to the db container with an uppercase connection alias prefix.
In addition to environment variables, Docker also adds host information to the / etc/hosts file of the parent container. The web container uses its own ID as the default hostname, and the db container uses db as the hostname.
For example, in the case of multiple web to db containers, you can link multiple child containers to the parent container.
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.