Differences between EXPOSE And Publish

The meaning of “EXPOSE and PUBLISH” are both used to expose the ports of containers to the outside world. But the use cases are different.

  1. EXPOSE: This is used in Dockerfile the port on which the container will listen to incoming connections. With the help of Docker “EXPOSE” others who are using the Docker image, they will get to know which port the container will listen to it EXPOSE does not actually publish the port and does not make the port accessible from outside the container.
  2. PUBLISH: This command is used to publish or map a port on the host computer to a port on the container when a container is first started. By using the docker run command, the host and container ports are mapped using the -p or —publish flag. As a result, additional services or customers can connect to the container over the mapped port and access the container port from outside the container.

In conclusion, PUBLISH is a runtime command that translates a container port to a host port, allowing external access to the container service over the specified port. EXPOSE is a statement in the Dockerfile that lists the ports on which the container listens.



How to Map Ports in Docker?

In docker, all the application in the container runs on particular ports when you run a container. If you want to access the particular application with the help of a port number you need to map the port number of the container with the port number of the docker host.

Similar Reads

Why We Use Port Mapping?

The network services of a container are made accessible to the host or external network through port mapping in Docker. Docker containers can only communicate with other containers on the same Docker network and run by default in isolation from the host and external networks. By publishing a container’s network service to the host or external network through port mapping, you can make it reachable from other networked devices....

Ways to Assign a New Port Mapping To A Running Container

There are a few ways to assign a new port mapping to a running container in Docker:...

Steps To Map Ports Of Docker Container With Docker Host

In the implementation, we are going to download a Jenkins container from the docker hub and map the Jenkins container port number with the docker host port number....

Publishing Docker Ports Via -P or -p

1. Map The Host Ports To Specific Ports Like TCP or UDP...

Check The published Ports Of A Running Docker Container

1. List All The Mapped Ports Of TheContainer...

Run Docker Container In Detached Mode

Most of the time you need to run the container in the detached mode or we can say in the background. By this, the application will continuously run when we are not engaged by this we can work on the remaining features of containers like networks or volumes of containers and also we can work on different multiple containers. To run the container in “detached” mode use the below command....

List containers In Docker

How do we know whether our container is running or not and know if any other containers are running in the Docker cluster? By using the below command we can know all the containers that are running....

Stop, Start, And Resart Containers

In real-time we need to perform some upgrades or any other modifications to the containers then we can perform upgrades while the container is running but it is not good practice to do then in that time we will stop the container and perform our patches. For stopping the container we can we below command....

Exposing Docker Ports Via EXPOSE or –expose

The port is not actually published by the EXPOSE command. It serves as a form of documentation regarding which ports are meant to be released between the person who produces the image and the person who runs the container. Use the -p flag on docker run to actually publish and map one or more ports when starting the container....

Differences between EXPOSE And Publish

The meaning of “EXPOSE and PUBLISH” are both used to expose the ports of containers to the outside world. But the use cases are different....