| ... | ... |
@@ -7,56 +7,75 @@ |
| 7 | 7 |
Create a redis service |
| 8 | 8 |
====================== |
| 9 | 9 |
|
| 10 |
-Very simple, no frills, redis service. |
|
| 10 |
+.. include:: example_header.inc |
|
| 11 | 11 |
|
| 12 |
-This example assumes you have Docker installed and the base image already |
|
| 13 |
-imported. |
|
| 12 |
+Very simple, no frills, redis service. |
|
| 14 | 13 |
|
| 15 | 14 |
Open a docker container |
| 16 | 15 |
----------------------- |
| 17 | 16 |
|
| 18 |
-:: |
|
| 17 |
+.. code-block:: bash |
|
| 19 | 18 |
|
| 20 |
- $ docker run -i -t base /bin/bash |
|
| 19 |
+ docker run -i -t base /bin/bash |
|
| 21 | 20 |
|
| 22 | 21 |
Building your image |
| 23 | 22 |
------------------- |
| 24 | 23 |
|
| 25 |
-Within your docker container. Once installed, <ctl-c> out of docker. |
|
| 24 |
+Update your docker container, install the redis server. Once installed, exit out of docker. |
|
| 26 | 25 |
|
| 27 |
-:: |
|
| 26 |
+.. code-block:: bash |
|
| 28 | 27 |
|
| 29 |
- $ apt-get update |
|
| 30 |
- $ apt-get install redis-server |
|
| 31 |
- SIGINT received |
|
| 28 |
+ apt-get update |
|
| 29 |
+ apt-get install redis-server |
|
| 30 |
+ exit |
|
| 32 | 31 |
|
| 33 | 32 |
Snapshot the installation |
| 34 | 33 |
------------------------- |
| 35 | 34 |
|
| 36 |
-:: |
|
| 35 |
+.. code-block:: bash |
|
| 37 | 36 |
|
| 38 |
- $ docker ps # grab the container id |
|
| 39 |
- $ docker commit <container_id> <your username>/redis |
|
| 37 |
+ docker ps -a # grab the container id (this will be the last one in the list) |
|
| 38 |
+ docker commit <container_id> <your username>/redis |
|
| 40 | 39 |
|
| 41 | 40 |
Run the service |
| 42 | 41 |
--------------- |
| 43 | 42 |
|
| 44 | 43 |
Running the service with `-d` runs the container in detached mode, leaving the |
| 45 |
-container running in the background. |
|
| 46 |
-:: |
|
| 44 |
+container running in the background. Use your snapshot. |
|
| 45 |
+ |
|
| 46 |
+.. code-block:: bash |
|
| 47 |
+ |
|
| 48 |
+ docker run -d -p 6379 <your username>/redis /usr/bin/redis-server |
|
| 49 |
+ |
|
| 50 |
+Test 1 |
|
| 51 |
+ |
|
| 52 |
+Connect to the container with the redis-cli. |
|
| 53 |
+ |
|
| 54 |
+.. code-block:: bash |
|
| 55 |
+ |
|
| 56 |
+ docker ps # grab the new container id |
|
| 57 |
+ docker inspect <container_id> # grab the ipaddress of the container |
|
| 58 |
+ redis-cli -h <ipaddress> -p 6379 |
|
| 59 |
+ redis 10.0.3.32:6379> set docker awesome |
|
| 60 |
+ OK |
|
| 61 |
+ redis 10.0.3.32:6379> get docker |
|
| 62 |
+ "awesome" |
|
| 63 |
+ redis 10.0.3.32:6379> exit |
|
| 47 | 64 |
|
| 48 |
- $ docker run -d -p 6379 -i -t <your username>/redis /usr/bin/redis-server |
|
| 65 |
+Test 2 |
|
| 49 | 66 |
|
| 50 |
-Test |
|
| 67 |
+Connect to the host os with the redis-cli. |
|
| 51 | 68 |
|
| 52 |
-:: |
|
| 69 |
+.. code-block:: bash |
|
| 53 | 70 |
|
| 54 |
- $ docker ps # grab the new container id |
|
| 55 |
- $ docker inspect <container_id> # grab the ipaddress |
|
| 56 |
- $ docker port <container_id> 6379 # grab the external port |
|
| 57 |
- $ redis-cli -h <ipaddress> -p <external port> |
|
| 58 |
- redis 10.0.3.32:49175> set docker awesome |
|
| 71 |
+ docker ps # grab the new container id |
|
| 72 |
+ docker port <container_id> 6379 # grab the external port |
|
| 73 |
+ ifconfig # grab the host ip address |
|
| 74 |
+ redis-cli -h <host ipaddress> -p <external port> |
|
| 75 |
+ redis 192.168.0.1:49153> set docker awesome |
|
| 59 | 76 |
OK |
| 60 |
- redis 10.0.3.32:49175> get docker |
|
| 77 |
+ redis 192.168.0.1:49153> get docker |
|
| 61 | 78 |
"awesome" |
| 79 |
+ redis 192.168.0.1:49153> exit |