In in docker-compose.yml file, there are options for ports
and expose
. How are they different?
相关问题
- Docker task in Azure devops won't accept "$(pw
- Unable to run mariadb when mount volume
- Unspecified error (0x80004005) while running a Doc
- What would prevent code running in a Docker contai
- How to reload apache in php-apache docker containe
According to the docker-compose reference,
Ports is defined as:
My
docker-compose.yml
looks like:If I do
docker-compose ps
, it will look like:Expose is defined as:
Ports are not exposed to host machines, only exposed to other services.
If I do
docker-compose ps
, it will look like:Ports This section is used to define the mapping between the host server and Docker container.
It means the application running inside the container is exposed at port 80. But external system/entity cannot access it, so it need to be mapped to host server port.
Note: you have to open the host port 10005 and modify firewall rules to allow external entities to access the application.
They can use
something like this
EXPOSE This is exclusively used to define the port on which application is running inside the docker container.
You can define it in dockerfile as well. Generally, it is good and widely used practice to define EXPOSE inside dockerfile because very rarely anyone run them on other port than default 80 port