running_redis_service.rst 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. :title: Running a Redis service
  2. :description: Installing and running an redis service
  3. :keywords: docker, example, package installation, networking, redis
  4. .. _running_redis_service:
  5. Create a redis service
  6. ======================
  7. .. include:: example_header.inc
  8. Very simple, no frills, redis service.
  9. Open a docker container
  10. -----------------------
  11. .. code-block:: bash
  12. docker run -i -t base /bin/bash
  13. Building your image
  14. -------------------
  15. Update your docker container, install the redis server. Once installed, exit out of docker.
  16. .. code-block:: bash
  17. apt-get update
  18. apt-get install redis-server
  19. exit
  20. Snapshot the installation
  21. -------------------------
  22. .. code-block:: bash
  23. docker ps -a # grab the container id (this will be the last one in the list)
  24. docker commit <container_id> <your username>/redis
  25. Run the service
  26. ---------------
  27. Running the service with `-d` runs the container in detached mode, leaving the
  28. container running in the background. Use your snapshot.
  29. .. code-block:: bash
  30. docker run -d -p 6379 <your username>/redis /usr/bin/redis-server
  31. Test 1
  32. ++++++
  33. Connect to the container with the redis-cli.
  34. .. code-block:: bash
  35. docker ps # grab the new container id
  36. docker inspect <container_id> # grab the ipaddress of the container
  37. redis-cli -h <ipaddress> -p 6379
  38. redis 10.0.3.32:6379> set docker awesome
  39. OK
  40. redis 10.0.3.32:6379> get docker
  41. "awesome"
  42. redis 10.0.3.32:6379> exit
  43. Test 2
  44. ++++++
  45. Connect to the host os with the redis-cli.
  46. .. code-block:: bash
  47. docker ps # grab the new container id
  48. docker port <container_id> 6379 # grab the external port
  49. ifconfig # grab the host ip address
  50. redis-cli -h <host ipaddress> -p <external port>
  51. redis 192.168.0.1:49153> set docker awesome
  52. OK
  53. redis 192.168.0.1:49153> get docker
  54. "awesome"
  55. redis 192.168.0.1:49153> exit