There are two ways to expose container ports in docker-compose: ports and expose. ports Ports exposes the container port to any port or specified port of the host. Usage: ports: - "80:80" # Bind the container's port 80 to the host's port 80 - "9000:8080" # Bind the container's port 8080 to the host's port 9000 - "443" # Bind the container's port 443 to any port on the host. The bound host port number is randomly assigned when the container starts Using ports will expose the port to the host regardless of whether the host port is specified or not. Some network applications can be run in the container. To make these applications accessible to the outside world, you can specify port mapping using the -P (uppercase) or -p (lowercase) parameters. (1) When the -P flag is used, Docker will randomly map a port between 49000 and 49900 to the network port opened inside the container. Using docker ps, you can see that port 49155 of the local host is mapped to port 5000 of the container. At this time, access port 49155 of the local machine to access the interface provided by the web application in the container. $ sudo docker run -d -P training/webapp python app.py $ sudo docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bc533791f3f5 training/webapp:latest python app.py 5 seconds ago Up 2 seconds 0.0.0.0:49155->5000/tcp nostalgic_morse Similarly, you can use the docker logs command to view application information. $ sudo docker logs -f nostalgic_morse * Running on http://0.0.0.0:5000/ 10.0.2.2 - - [23/May/2014 20:16:31] "GET / HTTP/1.1" 200 - 10.0.2.2 - - [23/May/2014 20:16:31] "GET /favicon.ico HTTP/1.1" 404 - (2) -p (lowercase) can specify the IP and port to be mapped, but only one container can be bound to a specified port. The supported formats are hostPort:containerPort, ip:hostPort:containerPort, ip::containerPort. expose Expose the container to the container linked to the current container. Usage: expose: - "3000" - "8000" The above instructions expose ports 3000 and 8000 of the current container to the container linked to this container. The difference from ports is that expose does not expose the port to the host. 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:
|
<<: Webpack file packaging error exception
>>: Detailed explanation of mysql scheduled tasks (event events)
1. MySQL transaction concept MySQL transactions a...
Vue recommends using templates to create your HTM...
This article mainly introduces an example of Vue ...
one. Remote deployment using tomcat 1.1 Problems ...
Table of contents 1. Nginx installation and start...
This article example shares the specific code of ...
I encountered this problem before when developing...
Configure Git environment in Docker At work, I en...
In actual development, the primary key of MySQL c...
Table of contents 1. Timer monitoring 2. Event mo...
I believe everyone has played scratch tickets. Wh...
Table of contents 1. What is componentization? 2....
Documentation: https://github.com/hilongjw/vue-la...
Git is integrated in vscode, and many operations ...
Pixel Resolution What we usually call monitor res...