CentOS 7.7 1908 安装使用 Docker 配置 Redis

  1. 安装 Docker:
    yum -y install docker
  2. Docker 状态相关:
    1. 状态:
      systemctl status docker.service
    2. 开启:
      systemctl start docker.service
    3. 停止:
      systemctl stop docker.service
    4. 查看开机启动状态:
      systemctl list-unit-files | grep docker.service
    5. 开启开机自启:
      systemctl enable docker.service
    6. 停止开机自启:
      systemctl disable docker.service
  3. 配置阿里云镜像:
    1. 编辑 /etc/docker/daemon.json 文件:
      vim /etc/docker/daemon.json
    2. 增加内容如下:
      {
        "registry-mirrors": ["https://hnkfbj7x.mirror.aliyuncs.com"]
      }
    3. 重启 Docker:
      systemctl restart docker
      systemctl daemon-reload
    4. 查看 Docker 配置是否生效:
      [root@localhost ~]# docker info 
      Containers: 0
       Running: 0
       Paused: 0
       Stopped: 0
      Images: 0
      Server Version: 1.13.1
      Storage Driver: overlay2
       Backing Filesystem: xfs
       Supports d_type: true
       Native Overlay Diff: true
      Logging Driver: journald
      Cgroup Driver: systemd
      Plugins: 
       Volume: local
       Network: bridge host macvlan null overlay
      Swarm: inactive
      Runtimes: runc docker-runc
      Default Runtime: docker-runc
      Init Binary: /usr/libexec/docker/docker-init-current
      containerd version:  (expected: aa8187dbd3b7ad67d8e5e3a15115d3eef43a7ed1)
      runc version: 66aedde759f33c190954815fb765eedc1d782dd9 (expected: 9df8b306d01f59d3a8029be411de015b7304dd8f)
      init version: fec3683b971d9c3ef73f284f176672c44b448662 (expected: 949e6facb77383876aeff8a6944dde66b3089574)
      Security Options:
       seccomp
        WARNING: You're not using the default seccomp profile
        Profile: /etc/docker/seccomp.json
       selinux
      Kernel Version: 3.10.0-1062.el7.x86_64
      Operating System: CentOS Linux 7 (Core)
      OSType: linux
      Architecture: x86_64
      Number of Docker Hooks: 3
      CPUs: 8
      Total Memory: 1.777 GiB
      Name: localhost.localdomain
      ID: BNQ7:7U3M:XLXK:PQ5T:LOCJ:JN6M:JCGR:2QKQ:SACU:5B7V:NCYU:BLNY
      Docker Root Dir: /var/lib/docker
      Debug Mode (client): false
      Debug Mode (server): false
      Registry: https://index.docker.io/v1/
      WARNING: bridge-nf-call-iptables is disabled
      WARNING: bridge-nf-call-ip6tables is disabled
      Experimental: false
      Insecure Registries:
       127.0.0.0/8
      Registry Mirrors:
       https://hnkfbj7x.mirror.aliyuncs.com
      Live Restore Enabled: false
      Registries: docker.io (secure)
      [root@localhost ~]# 
      
  4. 自定义 Docker 软件安装位置:
    由上可知,Docker 安装位置:Docker Root Dir: /var/lib/docker
    可使用命令直接查看:
    docker info | grep "Docker Root Dir"
     
    1. 停止 Docker:
      systemctl stop docker
    2. 修改 /etc/docker/daemon.json:
      vim /etc/docker/daemon.json
      内容如下:
      {
        "registry-mirrors": ["https://hnkfbj7x.mirror.aliyuncs.com"],
        "graph": "/data/docker"
      }
    3. 创建文件夹并建立链接:
      mkdir /data
      mv /var/lib/docker/ /data
      ln -s /data/docker/ /var/lib/docker
    4. 启动 Docker:
      systemctl start docker
    5. 查看 Docker 软件安装位置:
      docker info | grep "Docker Root Dir"
  5. 安装 Redis:
    1. 搜索 Redis:
      docker search redis
    2. 安装:
      docker pull redis
    3. 查看已安装镜像:
      docker images
      运行结果:
      [root@localhost ~]# docker images
      REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
      docker.io/redis     latest              36304d3b4540        11 days ago         104 MB
      [root@localhost ~]#
    4. 删除镜像:
      docker rmi redis
    5. 启动 Redis 并生成唯一标识:
      Docker 容器中的端口与本机、本机局域网是不互通的。
      1. 仅 Docker 使用:
        docker run --name d-redis -d redis
        说明:--name:为容器取别名,唯一标识
         
      2. 可本机、本机局域网使用:
        docker run -p 16379:6379 --name d-redis -d redis
      3. 设置密码:
        docker run -p 16379:6379 --name d-redis -d redis --requirepass "123456"
      4. 设置开机自启:
        docker run --restart=always -p 16379:6379 --name d-redis -d redis --requirepass "123456"
    6. 查看已运行容器:
      docker ps

      运行结果:
      [root@localhost ~]# docker ps
      CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
      ab3abbd4d7f4        redis               "docker-entrypoint..."   10 seconds ago      Up 9 seconds        6379/tcp            d-redis
      [root@localhost ~]# 
      
      或使用:
      docker ps -a
    7. 停止 Redis:
      docker stop d-redis
    8. 启动 Redis:
      docker start d-redis
    9. 查看容器日志:
      docker logs port-redis
    10. 开放 Redis 端口:
      firewall-cmd --zone=public --add-port=16379/tcp --permanent
      firewall-cmd --reload
      firewall-cmd --list-all
    11. 连接测试:

       
    12. 连接 Redis:
      docker exec -it d-redis redis-cli
      使用密码连接:
      docker exec -it d-redis redis-cli -h localhost -p 6379 -a 123456

      运行结果:
      [root@localhost ~]# docker exec -it d-redis redis-cli
      127.0.0.1:6379> 
      
  6. 安装指定版本的 Redis:
    docker pull redis:6.0

     
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值