www.icesr.com
IT运维工程师的摇篮

3.docker配置redis

3.docker配置redis

3.1 获取redis镜像

  • 获取镜像
<code>$ <span class="hljs-built_in">sudo</span> docker pull redis</code>
  • 查看镜像
<code>$ <span class="hljs-built_in">sudo</span> docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               latest              <span class="hljs-number">1</span>e70071f4af4        <span class="hljs-number">5</span> weeks ago         <span class="hljs-number">107</span>MB</code>

3.2 启动redis容器

<code><span class="hljs-comment"># 启动redis容器</span>
$ sudo docker run -p <span class="hljs-number">6379</span>:<span class="hljs-number">6379</span> <span class="hljs-comment">--name redis-master --restart=always -v /home/yangqian/docker-redis-data/redis-master/data:/data  -d redis redis-server --appendonly yes</span>
<span class="hljs-comment"># 查看容器进程</span>
$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
<span class="hljs-number">7</span>f35465997c4        redis               <span class="hljs-string">"docker-entrypoint.s…"</span>   <span class="hljs-number">6</span> <span class="hljs-built_in">seconds</span> ago       Up <span class="hljs-number">5</span> <span class="hljs-built_in">seconds</span>        <span class="hljs-number">0.0</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span>:<span class="hljs-number">6379</span>-&gt;<span class="hljs-number">6379</span>/tcp   redis-master
<span class="hljs-number">3</span>dc37943fb7a        mysql               <span class="hljs-string">"docker-entrypoint.s…"</span>   <span class="hljs-number">2</span> days ago          Up <span class="hljs-number">29</span> minutes       <span class="hljs-number">0.0</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span>:<span class="hljs-number">3307</span>-&gt;<span class="hljs-number">3306</span>/tcp   mysql-slave1
e37e29f090b7        mysql               <span class="hljs-string">"docker-entrypoint.s…"</span>   <span class="hljs-number">2</span> days ago          Up <span class="hljs-number">29</span> minutes       <span class="hljs-number">0.0</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span>:<span class="hljs-number">3306</span>-&gt;<span class="hljs-number">3306</span>/tcp   mysql-master

<span class="hljs-comment"># 查看redis容器的ip</span>
$ sudo docker inspect <span class="hljs-number">7</span>f |grep <span class="hljs-string">'IPAddress'</span>
            <span class="hljs-string">"SecondaryIPAddresses"</span>: <span class="hljs-constant">null</span>,
            <span class="hljs-string">"IPAddress"</span>: <span class="hljs-string">"172.17.0.4"</span>,
                    <span class="hljs-string">"IPAddress"</span>: <span class="hljs-string">"172.17.0.4"</span>,
<span class="hljs-comment"># 连接redis容器</span>
$ sudo docker run -<span class="hljs-keyword">it</span> redis redis-cli -h <span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.4</span>
<span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.4</span>:<span class="hljs-number">6379</span>&gt; <span class="hljs-built_in">set</span> name laowang
OK
<span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.4</span>:<span class="hljs-number">6379</span>&gt; mset class <span class="hljs-number">01</span> age <span class="hljs-number">18</span> gender man
OK
<span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.4</span>:<span class="hljs-number">6379</span>&gt; <span class="hljs-built_in">keys</span>
(error) ERR wrong <span class="hljs-built_in">number</span> <span class="hljs-operator">of</span> arguments <span class="hljs-keyword">for</span> <span class="hljs-string">'keys'</span> <span class="hljs-command"><span class="hljs-keyword">command</span></span>
<span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.4</span>:<span class="hljs-number">6379</span>&gt; <span class="hljs-built_in">keys</span> *
<span class="hljs-number">1</span>) <span class="hljs-string">"gender"</span>
<span class="hljs-number">2</span>) <span class="hljs-string">"name"</span>
<span class="hljs-number">3</span>) <span class="hljs-string">"class"</span>
<span class="hljs-number">4</span>) <span class="hljs-string">"age"</span>
</code>

未经允许不得转载:冰点网络 » 3.docker配置redis

分享到:更多 ()

评论 抢沙发

评论前必须登录!