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
278 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
• 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,510 points
547 views
0 votes
1 answer
0 votes
1 answer
0 votes
0 answers

what is the use of docker history command in Docker?

I am trying to find the initial ...READ MORE

Jun 19 in Docker by Shubham
• 1,000 points
17 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,520 points
136 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
• 39,330 points
2,116 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
67 views