Leon Overweel
Leon Overweel

Reputation: 1567

Does specifying ports in a docker-compose file override the ports exposed in a Dockerfile?

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.)

Upvotes: 2

Views: 2503

Answers (1)

prisar
prisar

Reputation: 3195

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.

Upvotes: 4

Related Questions