Install Redis Docker

broken image


Redis and Express are tools that provide a simple and clean approach to their problem domains. What follows is a Docker/Docker Compose v2 setup.

  1. Docker-compose Install Redis
  2. Setup Redis Docker
  3. Dockerfile Install Redis
  4. Install Redis Docker Image
  • The standalone install is a simple tarball with a binary. It contains its own node.js binary and will autoupdate like the above install methods. To quickly setup into /usr/local/lib/heroku and /usr/local/bin/heroku, run this script (script requires sudo and not Windows compatible).
  • I also have the same problem, first I tried to restart redis-server by sudo service restart but the problem still remained. Then I removed redis-server by sudo apt-get purge redis-server and install it again by sudo apt-get install redis-server and then the redis was working again.
  • Docker volumes allow you to back up, restore, and migrate data easily. This tutorial explains what a Docker volume is and how to use it, as well as how to mount a volume in Docker.

We would like to show you a description here but the site won't allow us. Prefer a fixed version than the latest that could be an unexpected version. Ex: traefik:v2.1.4 Docker images are based from the Alpine Linux Official image.; Any orchestrator using docker images can fetch the official Traefik docker image.

The repo is available at: https://github.com/HugoDF/express-redis-docker.

The docker-compose.yml is available at: github.com/HugoDF/express-redis-docker/docker-compose.yml

Redis is 'an open source, in-memory data structure store, used as a database, cache and message broker'. It's as simple and unopinionated as a database as it gets, it's known for its performance and simplicity as a key-value store. It has great flexibility and can also be used as a message queue, circular buffer (and pretty much anything else a developer can come up with short of a relational database).

Express is a 'fast, unopinionated, minimalist web framework for Node.js'. In other words, it's a wrapper around Node's server, that provides a way to write what's called 'middleware' to share and compose functionality across HTTP endpoints as well as define said endpoints.

Getting Redis and Express to work together is trivial. Getting Redis and Express to work together in a way that's fool and future-proof, and reproducible across local and deployed environments, is slightly harder. That's where Docker and Docker Compose come in.

Docker is a containerisation system, Docker Compose is a way to define how multiple Docker containers interact. In the context of Node web application development, Docker tends to be used to define a container that has the required system-level dependencies (eg. Node version, any extra database drivers). Docker Compose would be used to define dependencies outside of the Node application, for example databases.

To start off, we should create a new directory/initialise npm:

We can then install Express:

And create a server.js file that looks like the following:

That can be run using:

We can check that it's working as expected

Docker-compose Install Redis

To begin you'll want to install Docker Community Edition (https://www.docker.com/community-edition).Then we can add a Dockerfile and a docker-compose.yml:

Now run the app inside of Docker/Docker Compose:

And check that it still works

Some extra context:

  • The Dockerfile defines what container the application will be running in (here a Node 10 default container)
  • docker-compose.yml:
    • build explains which image should be used by the app service definition (in this case, it points to what would be created by running the Dockerfile)
    • volumes defines what should be mounted where (in this case, we'll mount the whole directory as /var/www/app
    • ports maps ports from the host system to ports inside the container
    • environment sets environment variables for the container
    • command determines what will be run on startup of the container, here it runs npm install followed by the server startup command

Setup Redis Docker

To add Redis to our Express app we should use the redis package:

Then we should probably wrap all the callback-based methods we want to use (see the api docs for the redis package, https://github.com/NodeRedis/node_redis#api).Let's do this using a redis-client.js module:

To running Redis inside of Docker Compose in such a way that our app can access it:

We can now access the Redis client from the app container:

We can now create a HTTP API that will allow us to store data using query params and retrieve them using a get request (this isn't RESTful at all but oh well 🙂 ).

If you have any questions about the above code let me know @hugo__df. It is using a couple of more advanced features like async/await and destructuring as well as Express features to get query and path parameters (see https://expressjs.com/en/api.html#req.query, https://expressjs.com/en/api.html#req.params).

Get the app running again: docker-compose up

  1. Store some data:
  1. Retrieve that data:

Note to more advanced Express users, and API design gurus.The reason I used an old school query-param based system is to avoid the boilerplate of using body-parser with POST requests

Full repository available at: https://github.com/HugoDF/express-redis-docker

Cover photo by Ben Koorengevel on Unsplash

Get The Jest Handbook (100 pages)

Take your JavaScript testing to the next level by learning the ins and outs of Jest, the top JavaScript testing library.

or

Join 1000s of developers learning about Enterprise-grade Node.js & JavaScript

You can install Traefik with the following flavors:

Use the Official Docker Image¶

Choose one of the official Docker images and run it with one sample configuration file:

For more details, go to the Docker provider documentation

Tip

  • Prefer a fixed version than the latest that could be an unexpected version.ex: traefik:v2.1.4
  • Docker images are based from the Alpine Linux Official image.
  • Any orchestrator using docker images can fetch the official Traefik docker image.

Use the Helm Chart¶

Warning

The Traefik Chart from Helm's default charts repository is still using Traefik v1.7.

Traefik can be installed in Kubernetes using the Helm chart from https://github.com/traefik/traefik-helm-chart.

Ensure that the following requirements are met:

  • Kubernetes 1.14+
  • Helm version 3.x is installed

Dockerfile Install Redis

Add Traefik's chart repository to Helm:

You can update the chart repository by running:

And install it with the helm command line:

Helm Features

All Helm features are supported.For instance, installing the chart in a dedicated namespace:

Php

If you have any questions about the above code let me know @hugo__df. It is using a couple of more advanced features like async/await and destructuring as well as Express features to get query and path parameters (see https://expressjs.com/en/api.html#req.query, https://expressjs.com/en/api.html#req.params).

Get the app running again: docker-compose up

  1. Store some data:
  1. Retrieve that data:

Note to more advanced Express users, and API design gurus.The reason I used an old school query-param based system is to avoid the boilerplate of using body-parser with POST requests

Full repository available at: https://github.com/HugoDF/express-redis-docker

Cover photo by Ben Koorengevel on Unsplash

Get The Jest Handbook (100 pages)

Take your JavaScript testing to the next level by learning the ins and outs of Jest, the top JavaScript testing library.

or

Join 1000s of developers learning about Enterprise-grade Node.js & JavaScript

You can install Traefik with the following flavors:

Use the Official Docker Image¶

Choose one of the official Docker images and run it with one sample configuration file:

For more details, go to the Docker provider documentation

Tip

  • Prefer a fixed version than the latest that could be an unexpected version.ex: traefik:v2.1.4
  • Docker images are based from the Alpine Linux Official image.
  • Any orchestrator using docker images can fetch the official Traefik docker image.

Use the Helm Chart¶

Warning

The Traefik Chart from Helm's default charts repository is still using Traefik v1.7.

Traefik can be installed in Kubernetes using the Helm chart from https://github.com/traefik/traefik-helm-chart.

Ensure that the following requirements are met:

  • Kubernetes 1.14+
  • Helm version 3.x is installed

Dockerfile Install Redis

Add Traefik's chart repository to Helm:

You can update the chart repository by running:

And install it with the helm command line:

Helm Features

All Helm features are supported.For instance, installing the chart in a dedicated namespace:

Install in a Dedicated Namespace
Installing with Custom Values

You can customize the installation by specifying custom values,as with any helm chart.

The values are not (yet) documented, but are self-explanatory:you can look at the default values.yaml file to explore possibilities.

Install Redis Docker Image

You can also set Traefik command line flags using additionalArguments.Example of installation with logging set to DEBUG:

Using Helm CLIWith a custom values file

Exposing the Traefik dashboard¶

This HelmChart does not expose the Traefik dashboard by default, for security concerns.Thus, there are multiple ways to expose the dashboard.For instance, the dashboard access could be achieved through a port-forward :

Accessible with the url: http://127.0.0.1:9000/dashboard/

Another way would be to apply your own configuration, for instance,by defining and applying an IngressRoute CRD (kubectl apply -f dashboard.yaml):

Use the Binary Distribution¶

Grab the latest binary from the releases page.

Check the integrity of the downloaded file
LinuxmacOSWindows PowerShell
Extract the downloaded archive
LinuxmacOSWindows PowerShell

And run it:

Compile your Binary from the Sources¶

All the details are available in the Contributing Guide





broken image