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.

Kodekloud Support

Hi @Xavier.Vieira
This worked for me…
$ docker run -d --name webapp -p38080:8080 -e DB_Password=db_pass123 -e DB_Host=mysql-db --network wp-mysql-network kodekloud/simple-webapp-mysql

But I must say the question lagged information about the container port :frowning: