docker中使用redis

来源:互联网 发布:美容院连锁软件 编辑:程序博客网 时间:2024/06/06 06:44

docker pull redis  安装redis镜像

docker run -d -p 6379:6379 –name redis redis  创建并启动容器

安装nsenter:

proxychains4 wget https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.tar.gz

tar -xzvf util-linux-2.24.tar.gz

cd util-linux-2.24/

./configure --without-ncurses

make nsenter

sudo cp nsenter /usr/local/bin

将下述脚本保存为docker-enter:

#!/bin/shif [ -e $(dirname "$0")/nsenter ]; then    # with boot2docker, nsenter is not in the PATH but it is in the same folder    NSENTER=$(dirname "$0")/nsenterelse    NSENTER=nsenterfiif [ -z "$1" ]; then    echo "Usage: `basename "$0"` CONTAINER [COMMAND [ARG]...]"    echo ""    echo "Enters the Docker CONTAINER and executes the specified COMMAND."    echo "If COMMAND is not specified, runs an interactive shell in CONTAINER."else    PID=$(docker inspect --format "{{.State.Pid}}" "$1")    if [ -z "$PID" ]; then        exit 1    fi    shift    OPTS="--target $PID --mount --uts --ipc --net --pid --"    if [ -z "$1" ]; then        # No command given.        # Use su to clear all host environment variables except for TERM,        # initialize the environment variables HOME, SHELL, USER, LOGNAME, PATH,        # and start a login shell.        "$NSENTER" $OPTS su - root    else       # Use env to clear all host environment variables.       "$NSENTER" $OPTS env --ignore-environment -- "$@"    fifi


给执行权限

chmod +x docker-enter

./docker-enter <image-id> 进入容器

测试redis:

root@816ebd247014:~# redis-cli ping
PONG
root@816ebd247014:~# redis-cli
127.0.0.1:6379> set myname jumping
OK
127.0.0.1:6379> get myname
“jumping”
127.0.0.1:6379>exit 退出容器

也可docker logs redis查看redis启动日志

也可使用RedisDesktopManager尝试连接

原创粉丝点击