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
4,343 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
8,148 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,190 points
3,557 views
+2 votes
1 answer
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
7,677 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,340 points
15,813 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
4,179 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