Sitemap
DevOps.dev

Devops.dev is a community of DevOps enthusiasts sharing insight, stories, and the latest development in the field.

Local Web Development Setup with Docker

Every Tinkerer Needs Their Tools

4 min readMay 14, 2024

--

Press enter or click to view image in full size

A developer has an ever-growing toolkit, let’s build the tool box. Countless “support” services are often incorporated into web development projects. It becomes a pain to start up a local MySQL instances and the like every time you boot up. It only becomes more of an issue as you begin to develop and test more services. At a corporate level you may be given a server with each service you will use wrapped up neatly to data dump to your hearts content, but many of us need to fiddle at home. For this I use a docker-compose configuration where I can easily deploy my entire supporting cast with a quick CLI command. Let’s get into it.

The Services

In typical fashion, I am prepared to start you off with some services I frequent. These would be Redis, RabbitMQ and MySql. To develop on these services and test they are up and running, you will need the following:

  • Redis-tools: Install with sudo apt-get redis-tools or mac with homebrew brew install redis
  • I will use DBeaver to connect to the MySQL instance, though this can be done in the CLI.
  • Docker-Hub: You need to start docker on your machine, an easy way to do this is to run docker-hub desktop.

The Config

This is where the magic🧙 Happens! This config will pull the given images from docker hub and deploy them to the given ports locally, then we can connect away! Note the “volumes” section of each service, which references a “docker-conf” folder in the same directory as the config. This is extremely important, it ties the storage for each service container to a location outside the container. This way the data saved to these services will persist when the container is closed.

Deployment and Testing

With this config you need only a bit more magic to begin interacting with these services. With this command you will spin up containers built from the provided images docker-compose -f docker-toolkit.yml up -d, here the -d switch detaches the command so it will run in the background (and you can continue to use this terminal).

Get Ken Foss’s stories in your inbox

Join Medium for free to get updates from this writer.

Now that the services are up we can use them… let’s get on it.

Redis

  1. Connect to the service:redis-cli -h localhost -p 6379
  2. Create a key-value pair: set newkey “Hello World”
  3. Visualize the key: keys *
  4. Get the corresponding value: get newkey

RabbitMQ

  1. Navigate to the following url: http://localhost:15672/
  2. Enter username and password as “admin”
Press enter or click to view image in full size
RabbitMQ Console

MySql

My MySql settings are as follows in DBeaver, the password is “root”.

DBeaver Connection Configuration

Now, I am going to create a table called “test”, I want to ensure it persists when the container is restarted.

Press enter or click to view image in full size
Create Table, use the highlighted save button to generate

Success! Upon restarting of the container our table is there just how we created it.

Press enter or click to view image in full size
Persistent Data in SQL

Restarting Your Containers

There is no need to run the docker-compose every time you start these services. The containers persist even as you restart your machine. If we go into docker desktop we can see these services and restart them.

Press enter or click to view image in full size
Docker Desktop — Containers

Now, you can restart these containers with the “play” button. If you prefer CLI commands the following will show your available containers:

docker ps -a

And start a container of your choosing:

docker start my_container_name

--

--

Written by Ken Foss

Full Stack Software Engineer @Budderfly kenfoss.com

Published in DevOps.dev

Devops.dev is a community of DevOps enthusiasts sharing insight, stories, and the latest development in the field.