details meme

How to install Redis with Docker for local testing

In another article I suggest installing Redis with docker but do not tell how. In this article I cover how to get a Redis Image up and running with Docker locally.

First you need to install Docker for your system.  After you have Docker installed, next you need to download a Redis image. Here is a list of official redis images.

To get the image you can use the pull method.
To view all of the current images you have on your system type

docker image ls -a

You should see something like this if you have any redis downloaded.

docker image ls outpu
output of docker image ls -a

Next create and run a new container with this command:

docker run --name redis-5 -dp 127.0.0.1:6379:6379 redis

–name is how you tell it the name you want for the container mine is redis-3
-dp the -d starts in detached mode, the p is for port and mine maps 6379 to 6379 127.0.0.1:6379:6379 tells docker to start the container with an ipv4 of 127.0.0.1 and network the systems port 6379 to the containers port 6379 without the ipv4 part Docker starts with an ipv4 of 0.0.0.0 127.0.0.1 is localhost some systems may map 0.0.0.0 to localhost in the hosts file too. You an add almost any conforming IP you want here and that will be the IP for the container docker run creates.
Here is a link to the docker docs about networking. Here is a link to Learning Ocean about docker networking.
redis is the name of the image I want to use to create the container.

That command will output something like this.

output of docker run
docker run output

Notice in the image, I did not specify an IP so it starts with an ipv4 of 0.0.0.0 not very helpful.

Once you have created the container you can start and stop it with the docker stop and start commands.

You will need to install the redis-cli if you want to quickly test your redis docker container is working. I am using ubuntu so I just install the redis-tools package. If you are using something else you are in for a world of hurt, see this stack question.  Ubuntu makes programming easier for most things.

Now to test if your docker redis is working just type the following into your command line to interact with redis via cli

redis-cli

You should see the following output, just the ip and port means your redis is working

your redis is working if you see this

To learn more about how to configure your symfony app to use this redis connection read this article.

Links

Here is a nice article about how to remove old images and containers and clean docker up.

Remove multiple docker images at once. This is good for when you have a bunch of unused images. Use this command to view all images currently on your system

Learning Ocean Docker tutorials – some of the best information you can find on Docker



Posted

in

,

by

Tags:

Comments

2 responses to “How to install Redis with Docker for local testing”

  1. kakashikseer Avatar
    kakashikseer

    1. About 0.0.0.0. That’s IPv4 for “everything”. That means “I will be listening on every available interface on given port for incoming connections”

    2. About redis-cli. You can use the same redis image for redis-cli. Either with exec (the same container) `docker exec -it ‘redis-5’ redis-cli` or create another container with `docker run –rm -it –link ‘redis-5′ redis redis-cli -h redis-5’

    1. ramachandra Avatar
      ramachandra

      Thanks I had no idea that the redis image also contained the cli and you could do that. I haven’t found that information anywhere

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: