Docker Community Forums

Share and learn in the Docker community.

What is the difference between option -p and expose when running container

Hello eveyone!

Like title, I am a new learner in docker and I don’t understand so much about 2 definition above.

For example:

docker run --expose=22

And

docker run -p 5801:5801

Anyone can explain me? Thanks!

My website: https://blog.vu-review.com

The first one exposes a port INSIDE the container, the secony one publishes a container port on the host (as in maps a host port to a container port). If you want your container to be connectable from the outside world, you need to publish a port.