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.
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.
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.
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
You should see the following output, just the ip and port means your redis is working
To learn more about how to configure your symfony app to use this redis connection read this article.
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