热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Ubuntu下用Docker安装Redis镜像和使用Redis容器分享

1.安装Ubuntu2.用Putty登录UbuntuWelcometoUbuntu14.04.1LTS(GNU/Linux3.13.0-40-genericx86_64)*Documentation:https://help.ubuntu.com/SysteminformationasofWedDec3106:41

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 }}" )

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

Ubuntu 14.04下Redis安装及简单测试 http://www.linuxidc.com/Linux/2014-05/101544.htm

Redis集群明细文档 http://www.linuxidc.com/Linux/2013-09/90118.htm

Ubuntu 12.10下安装Redis(图文详解)+ Jedis连接Redis http://www.linuxidc.com/Linux/2013-06/85816.htm

Redis系列-安装部署维护篇 http://www.linuxidc.com/Linux/2012-12/75627.htm

CentOS 6.3安装Redis http://www.linuxidc.com/Linux/2012-12/75314.htm

Redis安装部署学习笔记 http://www.linuxidc.com/Linux/2014-07/104306.htm

Redis配置文件redis.conf 详解 http://www.linuxidc.com/Linux/2013-11/92524.htm

Redis 的详细介绍:请点这里
Redis 的下载地址:请点这里

更多Ubuntu相关信息见Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-01/111180.htm


推荐阅读
  • 在Docker中,将主机目录挂载到容器中作为volume使用时,常常会遇到文件权限问题。这是因为容器内外的UID不同所导致的。本文介绍了解决这个问题的方法,包括使用gosu和suexec工具以及在Dockerfile中配置volume的权限。通过这些方法,可以避免在使用Docker时出现无写权限的情况。 ... [详细]
  • 本文主要介绍关于linux文件描述符设置,centos7设置文件句柄数,centos7查看进程数的知识点,对【Linux之进程数和句柄数】和【linux句柄数含义】有兴趣的朋友可以看下由【东城绝神】投 ... [详细]
  • 本文介绍了Hyperledger Fabric外部链码构建与运行的相关知识,包括在Hyperledger Fabric 2.0版本之前链码构建和运行的困难性,外部构建模式的实现原理以及外部构建和运行API的使用方法。通过本文的介绍,读者可以了解到如何利用外部构建和运行的方式来实现链码的构建和运行,并且不再受限于特定的语言和部署环境。 ... [详细]
  • CentOS7.8下编译muduo库找不到Boost库报错的解决方法
    本文介绍了在CentOS7.8下编译muduo库时出现找不到Boost库报错的问题,并提供了解决方法。文章详细介绍了从Github上下载muduo和muduo-tutorial源代码的步骤,并指导如何编译muduo库。最后,作者提供了陈硕老师的Github链接和muduo库的简介。 ... [详细]
  • {moduleinfo:{card_count:[{count_phone:1,count:1}],search_count:[{count_phone:4 ... [详细]
  • DockerDataCenter系列(四)-离线安装UCP和DTR,Go语言社区,Golang程序员人脉社 ... [详细]
  • 随着我司的应用都开始容器化,相应的ETL流程也需要迁移到容器中。常规的SQL和shell脚本迁移之后执行基本没有问题,主要的问题在于数据接入使用kettle的场景下,kettle启 ... [详细]
  • 有意向可以发简历到邮箱内推.简历直达组内Leader.能做同事的话,内推奖励全给你. ... [详细]
  • docker容器的数据管理一:数据卷实现数据的永久化,完全独立于容 ... [详细]
  • systemd-nspawn可以创建最轻量级的容器(ns的意思就是namespace),本文的实验平台是Ubuntu16.04,x86_64机器。本文的目的是:在Ubuntu中用syst ... [详细]
  • 云原生边缘计算之KubeEdge简介及功能特点
    本文介绍了云原生边缘计算中的KubeEdge系统,该系统是一个开源系统,用于将容器化应用程序编排功能扩展到Edge的主机。它基于Kubernetes构建,并为网络应用程序提供基础架构支持。同时,KubeEdge具有离线模式、基于Kubernetes的节点、群集、应用程序和设备管理、资源优化等特点。此外,KubeEdge还支持跨平台工作,在私有、公共和混合云中都可以运行。同时,KubeEdge还提供数据管理和数据分析管道引擎的支持。最后,本文还介绍了KubeEdge系统生成证书的方法。 ... [详细]
  • 本文介绍了Linux Shell中括号和整数扩展的使用方法,包括命令组、命令替换、初始化数组以及算术表达式和逻辑判断的相关内容。括号中的命令将会在新开的子shell中顺序执行,括号中的变量不能被脚本余下的部分使用。命令替换可以用于将命令的标准输出作为另一个命令的输入。括号中的运算符和表达式符合C语言运算规则,可以用在整数扩展中进行算术计算和逻辑判断。 ... [详细]
  • 面试经验分享:华为面试四轮电话面试、一轮笔试、一轮主管视频面试、一轮hr视频面试
    最近有朋友去华为面试,面试经历包括四轮电话面试、一轮笔试、一轮主管视频面试、一轮hr视频面试。80%的人都在第一轮电话面试中失败,因为缺乏基础知识。面试问题涉及 ... [详细]
  • mysql自动打开文件_让docker中的mysql启动时自动执行sql文件
    本文提要本文目的不仅仅是创建一个MySQL的镜像,而是在其基础上再实现启动过程中自动导入数据及数据库用户的权限设置,并且在新创建出来的容器里自动启动My ... [详细]
  • 现象:[root@localhost~]#dockerrun-d-p9000:80centos:httpdbinsh-cusrlocalbinstart.shd5b2bd5a7bc ... [详细]
author-avatar
濮阳小贝
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有