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,620 points
176 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 6,900 points

Related Questions In Docker

0 votes
1 answer

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

Here is very basic explanation for image ...READ MORE

answered Sep 4, 2018 in Docker by Damon Salvatore
• 5,430 points
288 views
0 votes
1 answer
+1 vote
1 answer

What is the default amount of memory provided for Windows Docker containers?

Docker for Windows containers by default get: On ...READ MORE

answered Oct 25, 2018 in Docker by Sophie may
• 9,330 points
15 views
0 votes
1 answer
0 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
• 56,140 points
79 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
• 36,260 points
1,485 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
• 6,900 points
45 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.