Using Redis on Docker (docker-compose.yml) in PHP

This short article will show you how to use Redis on Docker (docker-compose.yml) and how to connect in in the PHP. We are using the Predis library so that we need to install the dependency first by running the following composer command.

Then we need to put the Redis image in our docker-compose.yml file as follow.

As you can see, It is on the app-network, so that I will need to declare the network too.

If we spin up the docker, the Redis will be running on the port 6379.

We can connect to the Redis as follow.

Setting the value.

Retrieving the value.

You can also specify the port, schema and other variables for the client. That’s it. That is how we use Redis with Docker in PHP.

Software Developer based in the UK, used to work in Singapore, but originally from Myanmar.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store