Ubuntu下用docker安装redis镜像和使用redis容器分享

Ubuntu下用docker安装redis镜像和使用redis容器分享

 

1. 安装Ubuntu

2. 用Putty登录Ubuntu

Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-40-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Wed Dec 31 06:41:16 UTC 2014

  System load:  0.01              Processes:              228
  Usage of /:   6.0% of 28.80GB   Users logged in:        0
  Memory usage: 11%               IP address for eth0:    10.205.178.22
  Swap usage:   0%                IP address for docker0: 172.17.42.1

  Graph this data and manage this system at:
    https://landscape.canonical.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

 

3. 拉取redis镜像

root@jumping:~# sudo docker pull redis:latest
redis:latest: The image you are pulling has been verified
eee46bd361c1: Pull complete
ff8650f588b2: Pull complete
130985f77ca0: Pull complete
4d81fff38a25: Pull complete
e6d98faa32e2: Pull complete
95d3849978c3: Pull complete
263f96794544: Pull complete
1ed9b7611cf5: Pull complete
451742990a7f: Pull complete
511136ea3c5a: Already exists
f10807909bc5: Already exists
f6fab3b798be: Already exists
1e6ac0ffed3b: Already exists
62ff5003ac9a: Already exists
e49d349e8a75: Already exists
61213f5a1710: Already exists
9feca322d1c7: Already exists
1aa8ce669b93: Already exists
Status: Downloaded newer image for redis:latest
root@jumping:~# sudo docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
redis                     latest              451742990a7f        11 days ago         111.2 MB

4. 启动redis容器

root@jumping:~# sudo docker run -t -i redis:latest
[1] 31 Dec 02:56:57.870 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 2.8.19 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in stand alone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

[1] 31 Dec 02:56:57.890 # Server started, Redis version 2.8.19
[1] 31 Dec 02:56:57.890 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[1] 31 Dec 02:56:57.891 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
[1] 31 Dec 02:56:57.891 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
[1] 31 Dec 02:56:57.891 * The server is now ready to accept connections on port 6379

5.Redis容器启动了,那接下来怎么办?

办法:把putty关了,然后从新进来putty

6. 怎么进入容器呢?

先安装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 b430d6f4ff00 ls
dirname: invalid option -- 's'
Try 'dirname --help' for more information.
bin  boot  data  dev  entrypoint.sh  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  selinux  srv  sys  tmp  usr  var
root@b430d6f4ff00:~#

注:这里大家看到有错误,是因为脚本中用到$(dirname "$0""), 大家可以直接echo "$0",我这边显示的是-su

7. 测试redis命令

进入容器后可以用redis-cli ping测试可以连接上本机刚才启动的redis-server不,返回PONG说明连接成功。

直接按redis-cli进入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>

8. 这样就简单的把redis启动起来了,要用起来大家还要把端口影射到宿主机器上,然后可以通过客户端来调用Redis:http://redis.io/clients

时间: 2024-10-09 08:03:35

Ubuntu下用docker安装redis镜像和使用redis容器分享的相关文章

《循序渐进学Docker》——第3章 Ubuntu下使用Docker 3.1 Docker的运行平台

第3章 Ubuntu下使用Docker 第2章我们介绍了在Windows下如何搭建一个Docker运行环境.这一章我们要切换环境,在Ubuntu系统下使用Docker.为什么要切换到Ubuntu下呢,还要从Docker的运行平台说起. 3.1 Docker的运行平台 首先,我们需要知道Docker可以在哪些操作系统下运行.截止到2016年3月底,几乎所有的Linux系统(如Red Hat Enterprise Linux(RHEL)/Centos.Debian/Ubuntu.gentoo.arc

ubuntu下用rvm安装ruby on rails出错,求各路大神帮忙~!

问题描述 ubuntu下用rvm安装ruby on rails出错,求各路大神帮忙~! ruby已经安装好: $ ruby -v ruby 2.2.1p85(2015-02-26 revision 49769) [x86_64linux] 国内服务器推荐替换 RubyGems 的到淘宝镜像: $ gem sources --remove https://rubygems.org/ $ gem sources -a http://ruby.taobao.org/ 回车后报错 ERROR: Whil

安装包-ubuntu下dateutil的安装

问题描述 ubuntu下dateutil的安装 操作:在ubuntu中virtualenv下运行程序 错误提示:ImportError: No module named dateutil 已完成:下载了dateutil.tar.gz并已解压,里面有setup.py 我在网上看的安装setup.py文件需要python setup.py install --安装路径. 问题1:请问在安装dateutil我应该在ubuntu哪个目录下操作,是放要运行的项目的那个目录还是随便一个目录就可以? 问题2:

ubuntu下acidbase的安装

问题描述 ubuntu下acidbase的安装 无法用apt-get install 安装上面提示无法找到软件包应该怎么办?求大神指导 解决方案 http://blog.chinaunix.net/uid-26347676-id-3138443.html 解决方案二: http://blog.csdn.net/jo_say/article/details/6296325

Ubuntu下vim的安装和基本配置简介

  安装和基本用法 1.用root账户登录Ubuntu,命令行中输入vim,如果未安装会得到下面的提示: 程序"vim"已包含在下列软件包中: * vim * vim-gnome * vim-tiny * vim-gtk * vim-nox 请尝试: 代码如下: apt-get install <选定的软件包> 按照提示输入 代码如下: apt-get install vim 安装. 2.安装完成后,输入vim会进入vim的标准模式,这时按键盘的i进入插入模式,在里面写点什

Ubuntu下nginx编译安装参数配置_nginx

安装依赖库: sudo apt-get install libgd2-xpm sudo apt-get install libgd2-xpm-dev sudo apt-get install libgeoip-dev sudo apt-get install libpcre3 sudo apt-get install libpcre3-dev sudo apt-get install libssl-dev sudo apt-get install openssl sudo apt-get ins

ubuntu下解决Ruby安装后缺少openssl的问题

  一开始尝试使用     sudo apt-get install libopenssl-ruby1.8     安装是安装成功了,但是仍然提示找不到openssl.还是决定从源码安装,首先确保ubuntu安装了openssl:     sudo apt-get install openssl     sudo apt-get install libssl-dev     sudo apt-get install libssl0.9.8         然后进入ruby源码目录下的/ext/o

Ubuntu下VIM的安装和基本用法

1.用root账户登录Ubuntu,命令行中输入vim,如果未安装会得到下面的提示: 程序"vim"已包含在下列软件包中:  * vim  * vim-gnome  * vim-tiny  * vim-gtk  * vim-nox 请尝试:apt-get install <选定的软件包> 按照提示输入apt-get install vim安装. 2.安装完成后,输入vim会进入vim的标准模式,这时按键盘的i进入插入模式,在里面写点什么吧. 3.按Esc推出插入模式,进入标

ubuntu下filefox浏览器安装flash插件【图文教程】

初装了ubuntu,发现用filefox浏览器不能播放音乐,不能播放视频,不能看flash动画(?澹??耸蹦憔?ut了.今天笔者向大家介绍简单的安装flash插件. step1:进入flash官网:https://get.adobe.com/flashplayer/?loc=cn step2:在左下角选择合适自己系统的版本的flash插件,并点击"立即下载".此处选择的是:".tar.gz,适用其它linux" step3:进入命令行,将方才下载的文件解压,命令如下