What is the difference between expose and publish in Docker

0 votes

I’m experimenting with dockerfiles and the use of expose and publish has been a major confusion.

In all the tutorials they first include the EXPOSE command in the dockerfile and then build an image from this dockerfile

$ docker build -t an_image - < Dockerfile

And then publish the same port as above when running the image

$ docker run -d -p 8080 an_image
Jul 18, 2018 in Docker by Kalgi
• 2,680 points
3,275 views

1 answer to this question.

0 votes

Basically, you have three options:

  • Neither specify EXPOSE nor -p -> If you do not specify any of those, the service in the     container will not be accessible from anywhere except from inside the container itself.
  • Only specify EXPOSE -> If you EXPOSE a port, the service in the container is not accessible from outside Docker, but from inside other Docker containers. So this is good for inter-container communication.
  • Specify EXPOSE and -p -> If you EXPOSE and -p a port, the service in the container is accessible from anywhere, even outside Docker.
answered Jul 18, 2018 by Nilesh
• 7,060 points

Related Questions In Docker

0 votes
3 answers

What is the difference between a Docker image and a container?

Images are read-only templates that contain a ...READ MORE

answered Aug 10, 2020 in Docker by Vishal
• 260 points
6,667 views
0 votes
1 answer
+1 vote
1 answer

what is the difference between docker swarm and kubernetes

Both Kubernetes and Docker Swarm are important ...READ MORE

answered Sep 24, 2019 in Docker by Sirajul
• 59,230 points
2,375 views
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,020 points
2,714 views
+1 vote
4 answers

Communication between multiple docker-compose projects

You just need to make sure that ...READ MORE

answered Jul 30, 2018 in Docker by Kalgi
• 52,350 points
14,525 views
0 votes
2 answers

How can I inspect the file system of a failed `docker build

Failed command is a build that has ...READ MORE

answered Aug 6, 2018 in Docker by Nilesh
• 7,060 points
3,131 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP