What is the difference between Ports and EXPOSE options?

Hello,
I have two questions:
1- The Ports option allows the host to communicate with that port and EXPOSE shares a port between containers. Right?

2- Is it better to use EXPOSE in Dockerfile or YAML file?

Cheers.

You can ask everything here or read what you were already suggested. This is another example of a topic which I already shared wih you before since it is in my tutorial. Let’s try again.

Expose does almost nothing. It is just information to other services. Doesn’t matter what the value is. You will still need to forward port to it (ports), but it can be recognized by reverse proxies.

1 Like

Hello,
Thank you so much for your reply.
I thank you for your good website. Unfortunately, some of the options in Docker are a bit strange for me. It is written on your website:

It only states that it is not required, so use it when you know it is necessary either because some automation depends on it or just because you like to document which port is used in a container.

What kind of automation?

You have used the EXPOSE option in the Dockerfile.

Automatic port forwarding, reverse poxies.

I did indeed to show it does nothing.