当前位置 : 主页 > 网络编程 > PHP >

Docker安装运行Redis

来源:互联网 收集:自由互联 发布时间:2023-10-08
拉取官方的镜像,(这个示例中,官方镜像也是stars最多的): zhoumatoMBP:~ zhou$ docker pull redis Using default tag: latest latest: Pulling from library/redis be8881be8156: Pull complete d6f5ea773ca3: Pull complete 7
拉取官方的镜像,(这个示例中,官方镜像也是stars最多的):

zhoumatoMBP:~ zhou$ 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 image for redis:latest
zhoumatoMBP:~ zhou$ /Users/zhou/Library/Containers/com.docker.docker/Data/
-bash: /Users/zhou/Library/Containers/com.docker.docker/Data/: is a directory
zhoumatoMBP:~ zhou$ ls /Users/zhou/Library/Containers/com.docker.docker/Data/
backend.sock tasks vpnkit.pcap.sock
docker.sock vms vpnkit.port.sock
osxfs.sock vpnkit.diag.sock
task.lock vpnkit.eth.sock

查看一下是否成功:

zhoumatoMBP:~ zhou$ docker images

REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 4e8db158f18d 8 days ago 83.4MB
zhoumatoMBP:~ zhou$ docker images redis
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 4e8db158f18d 8 days ago 83.4MB

启动镜像:

zhoumatoMacBook-Pro:~ zhou$ docker run -p 6379:6379 -d redis:latest redis-server
30e18792709c1e70ec93007731c80062e603ad01e06795d23d4bc6d4c8cdf3ea


ps:

菜鸟教程:
docker run -p 6379:6379 -v $PWD/data:/data -d redis:3.2 redis-server --appendonly yes

命令说明:
-p 6379:6379 : 将容器的6379端口映射到主机的6379端口
-v $PWD/data:/data : 将主机中当前目录下的data挂载到容器的/data
redis-server --appendonly yes : 在容器执行redis-server启动命令,并打开redis持久化配置

查看容器启动情况:

zhoumatoMBP:~ zhou$ docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d0b86da2f6b9 redis "docker-entrypoint.s…" 8 minutes ago Up 8 minutes 0.0.0.0:6379->6379/tcp thirsty_lichterman

连接redis的几种方式:

docker exec -ti d0b86 redis-cli

docker exec -ti d0b86 redis-cli -h localhost -p 6379
docker exec -ti d0b86 redis-cli -h 127.0.0.1 -p 6379
docker exec -ti d0b86 redis-cli -h 172.17.0.3 -p 6379
网友评论