running_redis_service.rst 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. 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. sudo docker run -i -t ubuntu /bin/bash
  13. Building your image
  14. -------------------
  15. Update your Docker container, install the Redis server. Once
  16. installed, exit out of the Docker container.
  17. .. code-block:: bash
  18. apt-get update
  19. apt-get install redis-server
  20. exit
  21. Snapshot the installation
  22. -------------------------
  23. .. code-block:: bash
  24. docker ps -a # grab the container id (this will be the first one in the list)
  25. docker commit <container_id> <your username>/redis
  26. Run the service
  27. ---------------
  28. Running the service with `-d` runs the container in detached mode, leaving the
  29. container running in the background. Use your snapshot.
  30. .. code-block:: bash
  31. sudo docker run -d -p 6379 <your username>/redis /usr/bin/redis-server
  32. Test 1
  33. ++++++
  34. Connect to the container with the redis-cli.
  35. .. code-block:: bash
  36. sudo docker ps # grab the new container id
  37. sudo docker inspect <container_id> # grab the ipaddress of the container
  38. redis-cli -h <ipaddress> -p 6379
  39. redis 10.0.3.32:6379> set docker awesome
  40. OK
  41. redis 10.0.3.32:6379> get docker
  42. "awesome"
  43. redis 10.0.3.32:6379> exit
  44. Test 2
  45. ++++++
  46. Connect to the host os with the redis-cli.
  47. .. code-block:: bash
  48. sudo docker ps # grab the new container id
  49. sudo docker port <container_id> 6379 # grab the external port
  50. ip addr show # grab the host ip address
  51. redis-cli -h <host ipaddress> -p <external port>
  52. redis 192.168.0.1:49153> set docker awesome
  53. OK
  54. redis 192.168.0.1:49153> get docker
  55. "awesome"
  56. redis 192.168.0.1:49153> exit