refs:
http://blog.csdn.net/yangzhenping/article/details/42297205
1. Ubuntu14.04安装docker(apt 安装后是1.6)
sudo apt-get install docker-io
2. 拉取redis镜像
root@jumping:~# sudo docker pull redis:latest
root@jumping:~# sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
redis latest 451742990a7f 11 days ago 111.2 MB
3. 启动redis容器
root@jumping:~# sudo docker run -t -i redis:latest
4. 查看docker容器
#docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
39d2dd0f8c6b redis:latest "/entrypoint.sh redi 6 minutes ago Up 6 minutes 6379/tcp dreamy_hawking
显然默认配置的redis不能满足要求,需要进一步修改,那么如何进入docker虚拟的服务器呢。
5. 怎么进入容器呢?
先安装NSenter:
cd /tmp; curl http://ftp.sjtu.edu.cn/sites/ftp.kernel.org/pub/linux/utils/util-linux/v2.25/util-linux-2.25.tar.gz | tar -zxf-; cd util-linux-2.25;
sudo apt-get install build-essential
sudo apt-get make
./configure --without-ncurses
make nsenter && sudo cp nsenter /usr/local/bin
方法一:
PID=$(docker inspect --format "{{ .State.Pid }}" <container>)
nsenter --target $PID --mount --uts --ipc --net --pid
方法二:
安装脚本(脚本参照:https://github.com/jpetazzo/nsenter/blob/master/docker-enter)
wget -P ~ https://github.com/yeasy/docker_practice/raw/master/_local/.bashrc_docker;
echo "[ -f ~/.bashrc_docker ] && . ~/.bashrc_docker" >> ~/.bashrc; source ~/.bashrc
最后,调用docker-enter进入容器:
root@jumping:/tmp# docker-enter<container>
此处方法中container为步骤4中的容器CONTAINER ID
6. 测试redis命令
进入容器后可以用redis-cli ping测试可以连接上本机刚才启动的redis-server不,返回PONG说明连接成功。
直接按redis-cli进入redis 命令测试下可以用不:
root@816ebd247014:~# redis-cli ping
PONG