Home > Operation and Maintenance > Docker > Where does docker configure the port?

Where does docker configure the port?

coldplay.xixi
Release: 2020-06-19 09:33:10
Original
3971 people have browsed it

Where does docker configure the port?

Where does docker configure the port?

Where docker configures the port:

1. Automatic mapping

# docker run -d -p 80 --name myweb 1311399350/myweb nginx -g "daemon off;"
Copy after login

- above p 80 will randomly open a port on the docker host (you can use the docker port command to view it, or docker ps can also see it, here it is 32768) and map it to port 80 in the container.

2. Specify mapping

In addition to automatic mapping, you can also specify the mapping relationship, such as:

# docker run -d -p 80:80 --name myweb 1311399350/myweb nginx -g "daemon off;"
# docker port myweb 80
0.0.0.0:80
Copy after login

It can be seen that the 80 of the host machine The port is mapped to port 80 of the container. There are pros and cons to such a designation. The advantage is that the port is known and needs to be used with care; the disadvantage is that multiple identical containers cannot be run and it is easy to conflict with the host application.

3. Expose the port specified by the EXPOSE directive in the dockerfile

We specify the port or port range exposed by the container in the dockerfile

EXPOSE 20010
EXPOSE 10011
Copy after login

Use capital letters The -P parameter exposes the port specified by the EXPOSE instruction in the dockerfile (the port in the container) to the local host and randomly binds it to the port of the local host.

# docker run -d -P --name myweb 1311399350/myweb nginx -g "daemon off;"
Copy after login

Use# docker port container containre-port to view the host port mapped by the container

# docker port myweb 80
0.0.0.0:32771
Copy after login

Recommended tutorial: "docker tutorial

The above is the detailed content of Where does docker configure the port?. 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