Ports clarifications

I’m a bit confused about ports.

For example, there was a lab where we are asked to run a new container based on the simple-webapp-mysql image and expose it to port 38080.

I know there’s two ways to expose ports:

  • using --expose
  • using -p

And here where my confusion starts.
For example, for -p I know there are two expected values. The host port and the internal docker port, separated by “:”. But in the assignment only one port is mentioned. This is the host port right? What is the other?
And the expose only expects a value? What is it and how does it knows the other value?

Sorry if the questions are too dumb but this part is really confusing to me.

Hello @Xavier.Vieira,

If you define one port only like this -p 8080, so in this case, you define the port host and your container is not accessible, but if you need to make your container accessible, you should add a public port.

Thanks,
Kodekloud Support