I have seen a docker run command line as following:
docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
This command launch the image rabbitmq:3-management With the option --it, it runs in the interactive mode, so we can execute commands inside the container while it is still running. With the option --name, it allow me to assign the rabbitmq name to my container.
What i dont understand is the -p option, why it is twice ?
I know that the only way to access the process is from inside of it. To allow external connections to the container, you have to open (publish) specific ports.
So it is working like: docker run -p 8080:80 [image_name]
.
so it this command i to map TCP port 80 in the container to port 8080 on the Docker host.
So my question is why it is like this
-p 5672:5672 -p 15672:15672 rabbitmq:3-management
Why i have -p twice ?
Why i have the same port 5672:5672 and 15672:15672
?
Thanks
RabbitMQ accepts TCP client connections (consumers, publishers) on port 5672
by default. So -p 5672:5672
means "map port 5672
on the host to port 5672
of this container".
The RabbitMQ Management UI is an HTTP server which listens on port 15672
by default. So -p 15672:15672
means "map port 15672
on the host to port 15672
of this container" so that you can access the management UI in a web browser like localhost:15672
.
In both cases, the number on the left is the host port number. If 5672
was a port you were already using on your host, you could map a different port on your host to the container like -p 95672:5672
.