Photo by Dominik Lückmann on Unsplash
When we develop something we all need to use some services such as PostgreSQL, Redis, RabbitMQ and many-many others. But I don't like the idea of installing each and every one of them on my local machine. So the idea of dockerizing everything looks very appealing.
In this article I'll show how to deploy three mentioned services locally with docker. And, as a bonus, easy way of configuring and monitoring our containers park via Portainer.
Bonus first
Portainer is such a great and powerful tool that I just love! Let's set it up and ease our next steps.
You need to create a volume with a simple terminal command
$ docker volume create portainer_data
and deploy Portainer
$ docker run -d -p 9443:9443 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
All of this you can find in deploy section on the official documentation.
Then finish the initial setup. Again, everything is described in the docs
After it's done you can navigate to localhost:9443 and see the Portainer dashboard.
Now you can monitor your containers, attach to them, check logs, see and remove unused images and volumes, and do everything you could do from the terminal. But you don't need to google or remember those lengthy commands.
Allright, let's go!
PostgreSQL
As we need to have a persistent storage for our DB let's create a volume. Go to "Volumes" tab in Portainer and push that "Add volume" button. Give it a name, e.g. pg_data and hit "Create the volume".
Then go to the "Containers" tab and smash the "Add container" button.
Set Name: pg, Image: postgres:latest, on "Manual network port publishing" click plus sign and enter 5432 for both "host" and "container".
Next in the "Advanced container settings" section leave everything as is on "Command and logging tab". Move to the "Volumes" tab, hit plus sign and map /var/lib/postgresql/data to our pg_data volume. After that to the "Env" tab. Set POSTGRES_PASSWORD to, well, root password for the database. Let's say it will be password. I also like to set unless stopped on the "Restart policy" tab. Now we are ready to smash that "Deploy the container" button above our advanced settings section.
Here is an example screenshot:
Where do I get those variables and values? Docker Hub! Just open the service page and it's all there.
Also you can do everything by hand, but I don't remember how to create a volume with a custom name and map that to a container.
And we can now connect to Postgres via localhost:5432 as postgres user and password password!
Redis
If Postgres was quite a handful, Redis is much easier. The steps are similar.
- Create volume
- Create container
- from redis:latest
- with port binding 6379:6379;
- map created volume to /data;
- and, optionally, set restart policy.
 
- from 
Boom, done!
RabbitMQ
Next in line is Rabbit. It's so easy I don't even want to repeat 😀
- Create volume
- Create container
- from rabbitmq:3-management
- with port bindings 5672:5672and15672:15672for management;
- map created volume to /var/lib/rabbitmq;
- and, if you want, set restart policy.
 
- from 
And again, done! 🎉
Summary
When using docker you can free yourself from the need to install every service you need. Not to mention if you need different versions of the same thing.
Hope this will ease your struggles with containers (if any) and you'll be able to focus on writing quality code!
 
 
              

 
    
Top comments (1)
This tool is excellent! I don't use docker daily, so I tend to forget all the docker cli commands. With this I won't have to bother, when I want to quickly setup db or redis :)