
This assumes you have installed Docker on Linux and Docker is running.
A Docker image contains the code used to create a Docker container, such as creating a Nginx web server, or a mySQL server, or a home grown app, and the list goes on. In this way, an image is like a template used to create a container. An image is kind of like a virtual machine, but much more light weight, using significantly less storage a memory (containers are usually megabytes in size).
The following command can be used to create a RabbitMQ image and container. Let's break down this command.
- The docker run command is used to create the container if it doesn't exist and to start the container.
- The --detach flag is used to run the container in the background.
- The --name option is used to name the container rabbitmq.
- The --publish 5672:5672 option used to listen on port 5672 for AMQ connections. This is the port an app would use to make a connection to RabbitMQ.
- The --publish 15672:15672 option used to listen on port 15672 for HTTP connections. This is the port that would be used to access the RabbitMQ web browser interface.
- The --restart unless-stopped option is used so that the container is started if the Docker server is restarted
- The rabbitmq:3.9-management image is used to create the container.
docker run
--detach
--name rabbitmq
--publish 5672:5672
--publish 15672:15672
--restart unless-stopped
rabbitmq:management
Or a specific version of RabbitMQ can be used (version 3.9 in this example).
docker run
--detach
--name rabbitmq
--publish 5672:5672
--publish 15672:15672
--restart unless-stopped
rabbitmq:3.9-management
The docker images command should include the rabbitmq image.
~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
rabbitmq management 105b54dc64f1 32 hours ago 253 MB
And the docker container ls command should show the container is up and running.
~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d937372c09ab9 rabbitmq:management "/docker-entrypoin..." 6 minutes ago Created rabbitmq
And you should be able to access the RabbitMQ management console at http://<hostname or IP address of your Docker server>:15672. The default username and password is guest and guest. You will most likely want to create a new user with the administrator tag, grant the user access to all virtual hosts, and then delete the guest account.
Did you find this article helpful?
If so, consider buying me a coffee over at