2

If I have a Dockerfile in a folder called foo with the following line:

EXPOSE 80

And I have a docker-compose that builds the container like this:

services:
  foo:
    build: foo
    ...
    ports:
     - "5000:5000"

On the host machine, I'm only able to reach port 5000, while 80 refuses to connect.

So what exactly happens? Does docker-compose completely override the Dockerfile's EXPOSE commands? Does port 80 get exposed to only other containers on the internal network?

(I'm not really asking because I have a problem -- I just saw that the EXPOSE 80 still happened to be in my Dockerfile and I'm curious if it affects anything.)

Leon Overweel
  • 1,488
  • 4
  • 17
  • 27
  • Possible duplicate of [What is the difference between "expose" and "publish" in Docker?](https://stackoverflow.com/questions/22111060/what-is-the-difference-between-expose-and-publish-in-docker) – David Maze Oct 02 '18 at 23:12

1 Answers1

3

If you are using docker-compose up, then the dockerfile ports will be overridden. When you use docker run, the ports mentioned in dockerfile will be exposed.

prisar
  • 3,041
  • 2
  • 26
  • 27