Docker simple tutorial: Connecting a Redis database through a container

Source: Internet
Author: User
Tags cassandra redis docker hub docker run install redis redis server

Preface
This article focuses on how to use the official Redis image and Docker container to build the REDIS-CLI and connect it to a redis image. Let's start with a brief introduction to Redis, a key-value storage system that, in addition to caching the scene, provides a lot of powerful functionality and is now a very popular database.

about Docker Image Warehouse
You can search the Docker hub for all the current applications and services, such as the Python language, MySQL database, etc., in the Docker hub. And there are so many mirrors in the Docker hub that we can search for a lot of results, no matter what keyword we search. This is because the purpose of the official Docker image warehouse is to organize the docker images of known sources and meet certain quality standards to be provided to the user. In general, I suggest that everyone try to use the official image provided by the Docker hub, you can see in the query results list of the current classification of the official image, the general official image will be highlighted in the list, and there will be labeled "official" words.
when pulling the image from the official image warehouse, the user name can be either empty or set to the library, for example, when the Casandra image is pulled, it can be set to be obtained from the Apache Cassandra Project. You can also run the following command on your terminal to find the Cassandra image in the Docker hub:
$docker Search Cassandra
when the Docker hub is queried this way, the system returns a message prompting the user that "the image you pulled has been verified", and seeing this message indicates that the mirror's checksum was verified by the Docker daemon, and the source is reliable.

quickly implement Docker-to-Redis connectivity
Gossip Less say, we enter the actual combat tutorial below. First, run the following command to pull the Redis image from the Docker hub:
$ docker Pull Redis
run the above command to download the image, Docker daemon will automatically output the Redis image source information, download status, after the download is complete, the system will also display the final status information.
after the image pull is complete, you can start the Redis container with the following command, remember to bring the "-D" parameter:
$ docker Run--name myredis-itsmine-d Redis
The function of the "-D" parameter is to let Redis run in the background, because this is the appropriate way to run the background in this case, so here we write this parameter. If you do not have the "-D" parameter, it will be troublesome to deal with, in which case we need to stop running the terminal or exit the container before we can access Redis through the host.
below we will take the most important step to connect Redis. Since we don't actually need to connect to Redis applications, we've used the REDIS-CLI tool here. You can install REDIS-CLI on the host, but I recommend that you create a new container, run the redis-cli inside, and then connect the two containers with the following command, so that we can see the detailed application information:
$docker Run--rm-it--link myredis-itsmine:redis redis/bin/bash
after running the command, we can see the container's message below the Bash command line:

[Email protected]:/data#
$ docker Run--rm-it--link Myredis:redis redis/bin/bash
$ [email protected]:/data# redis-cli-h redis-p 6379
$ redis:6379> Ping
$ PONG
$ redis:6379> Set "ABC" 123
$ OK
$ redis:6379> Get "ABC"
$ "123"
$ redis:6379> Exit
[Email protected]:/data# exit
$ exit

In the above command, the "–link Myredis-itsmine:redis" parameter followed by the Docker Run command is used to create the connection, and when Docker receives the instruction, it tries to connect our newly created container to the current " Myredis-itsmine "container, and the REDIS-CLI in the new container is named" Redis ". Docker creates a portal for Redis under the/etc/hosts path in the container and points to the IP address of the Myredis-itsmine container. This allows us to use "Redis" as the hostname directly in the REDIS-CLI, which is handy, and we don't have to find another way to "discover" the Redis IP address and then reference it.
we can then use the set and put commands to perform the Redis access operation, where we can experiment with some sample data. Of course, before starting the access operation, you will have to run the Redis ping command again to verify that the Redis server is connected.
This article describes how to implement the Redis database connection through the container, see here, have you already had a preliminary concept to the network connection of the container? The new Docker has also made some improvements in network functionality, and it is believed that in the near future all users will be able to easily interconnect applications and services through Docker containers.  


This article is from the "11424222" blog, please be sure to keep this source http://11434222.blog.51cto.com/11424222/1774247

Docker simple tutorial: Connecting a Redis database through a container

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.