Up and running with Docker and Redis

Carlos Justiniano
Hydra Microservices

--

Install Docker and launch Redis on your Mac!

By far the easiest and most useful way to launch Redis is simply by installing Docker and running Redis as a container. If that sounds complex, hang in there — you won’t believe how easy that actually is!

First, visit the Docker website and download Docker CE for your Mac, Windows or Linux box. Once you have Docker installed you should be able to confirm it’s properly installed using the docker version command.

Next, let’s prepare Docker to run containers in a configuration called a swarm.

With Docker running, we’re ready to pull in Redis.

To do this we’ll utilize a Docker Stack for organizing containers within our cluster. This will only require creating three small files, a configuration file and two shell scripts.

Firstly, let’s create a Docker compose file, compose.yml, which will describe our stack.

Above we’re specifying that we’re using a network called servicenet and defining a single service called redis.

Next, let’s create our two shell scripts. The first, stackup.sh will launch our stack and the second, stackdn.sh will tear our stack down when we no longer need it.

stackup.sh
stackdn.sh

We launch our stack using stackup.sh:

Above we see that the stackup.sh script created a new network and a service called test_redis. It does that by reading the compose.yml we created earlier.

Using thedocker ps command we’re able to see the running container.

We can even access the Redis instance from outside of the swarm by using the docker exec command to execute the redis-cli command line client. We do need to supply the container instance ID we saw earlier.

And that’s all there is too it!

If you’re interested in running Docker and Redis on AWS, see my: Installing Docker CE on an AWS EC2 instance running Ubuntu 16.04. That might be useful if you’d rather setup a remote environment.

Thanks for reading! If you like what you read, hold the clap button below so that others may find this. You can also follow me on Twitter.

--

--

Carlos Justiniano
Hydra Microservices

Senior Vice President of Technology @ F45 Training. Former VP of Engineering @ Flywheel Sports. World record holder, author, photographer,