Docker run Command Example
In this tutorial, we will explain the basis of the Docker run command and for that, we will start a simple container (RabbitMQ in our case).
1. Introduction to Docker and RabbitMQ
Let us take a good look at the Docker and RabbitMQ terminology.
1.1 Introduction to Docker
In the present world, Docker is an important term:
- Often used in CI/CD platform that packages and runs the application with its dependencies inside a container
- Is a standard for Linux Containers
- A Container is a runtime that runs under any Linux kernel and provides a private machine-like space under Linux
1.1.1 Docker Terminology
- Image: Representation of Docker container i.e. a JAR or WAR file in Java
- Container: Runtime of Docker i.e. a deployed and running Docker image. For example, an executable Spring Boot jar
- Engine: The code that manages, creates and runs the Docker containers
- Hub: A public developers registry to distribute their code
- Repository: A collection of Docker related images i.e. different versions of the same application
1.1.2 Docker Command Basics
Here is an example command.
1.1.3 Need for using Docker
- For environment replication, while the code runs locally on the machine
- For numerous deployment phases i.e. Dev/Test/QA
- For version control and distributing the application’s OS within a team
1.1.4 Setting up Docker
If someone needs to go through the Docker installation, please watch this video.
1.2 Introduction to RabbitMQ: When is it often used?
- It is an AMQP messaging broker and is the famously easy to set up, open-source, and cross-platform message broker
- AMQP stands for Advanced Message Queuing protocol which offers features like Message Orientation, Queuing, Routing (through Point-to-Point or Publish-and-Subscribe), Reliability and Security
- It offers an easy way to exchange different platform applications (like Java and DotNet) and offers helps in communication between different Microservices
- It is a lightweight and easy to deploy application available on-premises and cloud to meet the high scalability and availability requirements
- In the present time, a single application supports multiple tasks (i.e. sending notifications, reports, etc.). So sometimes these tasks add an extra load on the application thereby increasing the maintenance cost (such as space, memory, etc) to serve more requests. Thus, RabbitMQ in such situations acts a blessing to remove some of the heavy tasks
2. Docker run Command Example
Here is a systematic guide for implementing this lab tutorial.
2.1 Application pre-requisite
To start RabbitMQ on Docker, I hope that readers at present have the Docker up and running on their machine.
2.2 Pull the image
This is the basic step where obtaining the RabbitMQ image for Docker is simple as issuing the docker pull
command against the registry.
Pull the Docker image
1 2 | # To pull the RabbitMQ image from the docker hub. docker pull rabbitmq:3-management |
2.3 Starting the RabbitMQ using Docker run command
For the tutorial purpose, we will keep it simple. To start the RabbitMQ just trigger the following command in the terminal.
Starting RabbitMQ
1 2 | # To start RabbitMQ on default port docker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3-management |
Please note, this will start a RabbitMQ container listening on the default port of 5672
. Now in case you are interested to run the RabbitMQ container on a different port other than the default, we can trigger the following command.
1 2 | # To start RabbitMQ on the port number other than the default port docker run -d --hostname my-rabbit -p <!--PORT_NUMBER_OF_YOUR_CHOICE--!>:15672 -p 5671:5671 -p 5672:5672 --name rabbitmq rabbitmq:3-management |
3. Output
Once the docker run
command is fired and if everything goes well, you can navigate to the following URL – localhost:15672
and you will get an output as shown in Fig. 2:
Users can log in via the default username/password (i.e. guest/guest). Try out these commands in your development environment to practice and learn.
4. Summary
In this tutorial, we:
- made an introduction to Docker and RabbitMQ
- checked commands to run RabbitMQ via the Docker run command
I hope the tutorial will help you to set up RabbitMQ on Docker using the Docker run command. Happy learning and do not forget to share!
5. Download the source code
You can download the full source code of this example here: Docker run Command Example
Last updated on Jan. 31st, 2022