Daily work have their own main development machine, in order to build a set of environment convenient daily development, usually choose to install some local server software such as mysql, nginx, etc..
Over time a lot of server software is installed locally, and upgrading and administration becomes particularly troublesome. Recently, I just need to build a Redis environment, so I started to gradually replace the current server application directly installed on the host system through docker image installation.
This paper recorded the whole process of building the Redis environment through Docker.
Install the cli
➜ : ~ kongfutech $wget ➜ : http://download.redis.io/releases/redis-5.0.5.tar.gz ~ kongfutech $tar XZF redis - 5.0.5. Tar. Gz ➜ : ~ kongfutech$cdRedis - 5.0.5 ➜ : ~ kongfutech $makeCopy the code
Redis-server and client redis-cli can be used to interact with the Redis server in the Docker container.
The installation image
1. Query a mirror.
➜:~ kongfutech$Docker Search Redis NAME DESCRIPTION STARS OFFICIAL AUTOMATED Redis redis an opensourceThe key value store - that... 7004 [OK] bitnami/redis Bitnami Redis Docker Image 114 [OK] sameersbn/redis 75 [OK] grokzen/redis-cluster Redis cluster 3.0, 3.2, 4.0 & 5.0 49 KubeGuide/Redis-Master With"Hello World!" 29
rediscommander/redis-commander Alpine image forRedis - commander - redis man... 25 [OK]Copy the code
2, pull mirror:
➜:~ kongfutech$docker pull redis Using default tag: latest latest: Pulling from library/redis be8881be8156: Pull complete d6f5ea773ca3: Pull complete 735cc65c0db4: Pull complete 787dddf99946: Pull complete 0733799a7c0a: Pull complete 6d250f04811a: Pull complete Digest: sha256:858b1677143e9f8455821881115e276f6177221de1c663d0abef9b2fda02d065 Status: Downloaded newer imageforRedis: latest ➜ : ~ kongfutech $/ Users/kongfutech/Library/Containers/com. The docker. The docker/Data / - bash: /Users/kongfutech/Library/Containers/com.docker.docker/Data/: Is a directory ➜ : ~ kongfutech $ls/Users/kongfutech/Library/Containers/com. The docker. The docker. / Data/backend sock tasks vpnkit.pcap.sock docker.sock vms vpnkit.port.sock osxfs.sock vpnkit.diag.sock task.lock vpnkit.eth.sockCopy the code
3, check whether it is successful:
➜:~ kongfutech$Docker images REPOSITORY TAG IMAGE ID CREATED SIZE Redis latest 4e8DB158F18d 8 days ago 83.4MB ➜:~ Kongfutech $Docker images Redis REPOSITORY TAG IMAGE ID CREATED SIZE Redis latest 4e8DB158F18d 8 days ago 83.4MBCopy the code
4, start mirror:
➜:~ kongfutech$docker run -p 6379:6379-v$PWD/data:/data -d redis:latest redis-server --appendonly yes
f2f6d7ba523b32dba90e08a077a47839c63b0d4da6e050637c1a6d02b51ae510
Copy the code
-p 6379:6379: Maps port 6379 of a container to port 6379 of a host -v $PWD/data:/data: Redis-server --appendonly YES: Run the redis-server startup command in the container and enable redis persistence
5. Check whether the startup is successful
➜:~ kongfutech$docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f2F6D7ba523b redis:latest"Docker - entrypoint. S..."10 minutes ago Up 10 minutes 0.0.0.0:6379->6379/ TCP sharp_kepler 10 minutes ago Up 10 minutes 0.0.0.0:6379->6379/ TCP sharp_keplerCopy the code
Verify the Redis service
Verify redis deployed in Docker using a Redis-CLI connection
➜:~ kongfutech$redis-cli -h 127.0.0.1 -p 6379 127.0.0.1:6379> keys * (empty list orset) 127.0.0.1:6379> Ping PONG 127.0.0.1:6379> 127.0.0.1:6379> ping PONG 127.0.0.1:6379>setSpring Spring Framework OK 127.0.0.1:6379> Get Spring"springframework"127.0.0.1:6379 > keys * 1)"spring"
2) "spring2"127.0.0.1:6379 > keys spring * 1)"spring"
2) "spring2"
Copy the code
conclusion
1, Linux or MAC can be directly compiled through the source installation of redis server and redis- CLI client; For Windows, you can download the executable installation package directly. Github.com/microsoftar…
2, through the official Docker image can be directly deployed in the container redis server. The application and the Redis – CLI client can interact with the Redis server. Dockerfile and other configuration files are used to manage the local development environment.
reference
- redis.io/download
- Redis. IO/commands/ke…
- Github.com/microsoftar…