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

本文涉及的产品
容器镜像服务 ACR,镜像仓库100个 不限时长
简介: Ubuntu下用docker安装redis镜像和使用redis容器分享 1. 安装Ubuntu2. 用Putty登录UbuntuWelcome to Ubuntu 14.

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

相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
4天前
|
Ubuntu 安全 网络安全
Docker镜像:Ubuntu支持systemctl、SSH和VNC
总的来说,Docker提供了一个灵活且强大的方式来创建和运行自定义的Ubuntu镜像。通过理解和使用Dockerfile,你可以轻松地创建一个支持systemctl、SSH和VNC的Ubuntu镜像。
71 21
|
16天前
|
NoSQL Redis 数据库
Docker平台上的Redis镜像运行
这就是如何在Docker平台上运行Redis镜像的全部过程。走进Docker和Redis的世界,探索更多可能!
65 10
|
19天前
|
NoSQL 数据可视化 关系型数据库
安装 Redis
本文主要介绍了Linux系统下Redis的安装步骤,包括卸载旧版本、下载新版本、编译安装以及配置启动等详细操作,并解释了Redis默认端口6379的由来。同时,文章还简要说明了Windows环境下Redis的下载与服务安装方法。最后,推荐了几款Redis可视化管理工具,如RedisView、QuickRedis、AnotherRedisDesktopManager和RedisPlus,提供了它们的功能特点及下载链接,方便用户根据需求选择合适的工具进行数据库管理。
|
22天前
|
安全 API 算法框架/工具
大模型文件Docker镜像化部署技术详解
大模型文件Docker镜像化部署技术详解
168 2
|
1月前
|
NoSQL Java Redis
微服务——SpringBoot使用归纳——Spring Boot 中集成Redis——Redis 安装
本教程介绍在 VMware 虚拟机(CentOS 7)或阿里云服务器中安装 Redis 的过程,包括安装 gcc 编译环境、下载 Redis(官网或 wget)、解压安装、修改配置文件(如 bind、daemonize、requirepass 等设置)、启动 Redis 服务及测试客户端连接。通过 set 和 get 命令验证安装是否成功。适用于初学者快速上手 Redis 部署。
34 0
|
1月前
|
存储 JSON 数据格式
docker load 后镜像名称为空的问题解决
Docker在容器化应用程序时提供了强大的镜像管理功能,但也可能在某些操作中遇到如镜像名称为空的问题。通过理解问题的成因并采取适当的解决方案,如正确保存和加载镜像、手动修复标签等,可以有效避免和解决这一问题。通过本文提供的指导,您可以确保在使用Docker进行镜像操作时更为顺利,并提高容器管理的效率。
168 82
|
1月前
|
SQL Linux 数据库
YashanDB Docker镜像制作
本文介绍了使用Docker部署YashanDB数据库的方法及其优势。相比传统部署方式,Docker简化了环境配置,实现一键部署,确保软件在不同环境中一致运行。文章详细讲解了数据库镜像与容器的概念、Dockerfile的构建流程,以及如何通过Dockerfile定制YashanDB镜像。此外,还演示了镜像的发布过程,包括推送至阿里云容器镜像服务(ACR)。最后,探讨了容器启动时的初始化脚本设置和数据文件复用方法,满足客户对数据库自动化初始化和数据持久化的需求。
|
4天前
|
Ubuntu Linux 编译器
在Ubuntu Linux系统下如何搭建并安装EDK2
以上就是在Ubuntu Linux系统下搭建并安装EDK2的过程。这个过程可能会有些复杂,但只要按照步骤一步步来,应该不会有太大问题。如果在过程中遇到任何问题,都可以在网上找到相应的解决方案。希望这个指南能对你有所帮助!
42 17
|
12天前
|
Ubuntu 关系型数据库 MySQL
在Ubuntu系统的Docker上安装MySQL的方法
以上的步骤就是在Ubuntu系统的Docker上安装MySQL的详细方法,希望对你有所帮助!
79 12
|
18天前
|
Ubuntu Linux
Ubuntu中dpkg和apt命令:debian包安装详解
希望这让你对于Ubuntu中的dpkg和apt命令有了更为清晰的理解。下次你面对软件包安装的问题,就可以轻松应对,优雅地在你的Linux系统中游刃有余了。
145 10