basics.rst 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. :title: Base commands
  2. :description: Common usage and commands
  3. :keywords: Examples, Usage
  4. The basics
  5. =============
  6. Starting Docker
  7. ---------------
  8. If you have used one of the quick install paths', Docker may have been installed with upstart, Ubuntu's
  9. system for starting processes at boot time. You should be able to run ``docker help`` and get output.
  10. If you get ``docker: command not found`` or something like ``/var/lib/docker/repositories: permission denied``
  11. you will need to specify the path to it and manually start it.
  12. .. code-block:: bash
  13. # Run docker in daemon mode
  14. sudo <path to>/docker -d &
  15. Running an interactive shell
  16. ----------------------------
  17. .. code-block:: bash
  18. # Download a base image
  19. docker pull base
  20. # Run an interactive shell in the base image,
  21. # allocate a tty, attach stdin and stdout
  22. docker run -i -t base /bin/bash
  23. Starting a long-running worker process
  24. --------------------------------------
  25. .. code-block:: bash
  26. # Start a very useful long-running process
  27. JOB=$(docker run -d base /bin/sh -c "while true; do echo Hello world; sleep 1; done")
  28. # Collect the output of the job so far
  29. docker logs $JOB
  30. # Kill the job
  31. docker kill $JOB
  32. Listing all running containers
  33. ------------------------------
  34. .. code-block:: bash
  35. docker ps
  36. Expose a service on a TCP port
  37. ------------------------------
  38. .. code-block:: bash
  39. # Expose port 4444 of this container, and tell netcat to listen on it
  40. JOB=$(docker run -d -p 4444 base /bin/nc -l -p 4444)
  41. # Which public port is NATed to my container?
  42. PORT=$(docker port $JOB 4444)
  43. # Connect to the public port via the host's public address
  44. # Please note that because of how routing works connecting to localhost or 127.0.0.1 $PORT will not work.
  45. IP=$(ifconfig eth0 | perl -n -e 'if (m/inet addr:([\d\.]+)/g) { print $1 }')
  46. echo hello world | nc $IP $PORT
  47. # Verify that the network connection worked
  48. echo "Daemon received: $(docker logs $JOB)"
  49. Committing (saving) an image
  50. -----------------------------
  51. Save your containers state to a container image, so the state can be re-used.
  52. When you commit your container only the differences between the image the container was created from
  53. and the current state of the container will be stored (as a diff). See which images you already have
  54. using ``docker images``
  55. .. code-block:: bash
  56. # Commit your container to a new named image
  57. docker commit <container_id> <some_name>
  58. # List your containers
  59. docker images
  60. You now have a image state from which you can create new instances.
  61. Read more about :ref:`working_with_the_repository` or continue to the complete :ref:`cli`