basics.rst 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ==============
  2. Docker Builder
  3. ==============
  4. .. contents:: Table of Contents
  5. 1. Format
  6. =========
  7. The Docker builder format is quite simple:
  8. ``instruction arguments``
  9. The first instruction must be `FROM`
  10. All instruction are to be placed in a file named `Dockerfile`
  11. In order to place comments within a Dockerfile, simply prefix the line with "`#`"
  12. 2. Instructions
  13. ===============
  14. Docker builder comes with a set of instructions:
  15. 1. FROM: Set from what image to build
  16. 2. RUN: Execute a command
  17. 3. INSERT: Insert a remote file (http) into the image
  18. 2.1 FROM
  19. --------
  20. ``FROM <image>``
  21. The `FROM` instruction must be the first one in order for Builder to know from where to run commands.
  22. `FROM` can also be used in order to build multiple images within a single Dockerfile
  23. 2.2 MAINTAINER
  24. --------------
  25. ``MAINTAINER <name>``
  26. The `MAINTAINER` instruction allow you to set the Author field of the generated images.
  27. This instruction is never automatically reset.
  28. 2.3 RUN
  29. -------
  30. ``RUN <command>``
  31. The `RUN` instruction is the main one, it allows you to execute any commands on the `FROM` image and to save the results.
  32. You can use as many `RUN` as you want within a Dockerfile, the commands will be executed on the result of the previous command.
  33. 2.4 CMD
  34. -------
  35. ``CMD <command>``
  36. The `CMD` instruction sets the command to be executed when running the image.
  37. It is equivalent to do `docker commit -run '{"Cmd": <command>}'` outside the builder.
  38. .. note::
  39. Do not confuse `RUN` with `CMD`. `RUN` actually run a command and save the result, `CMD` does not execute anything.
  40. 2.5 EXPOSE
  41. ----------
  42. ``EXPOSE <port> [<port>...]``
  43. The `EXPOSE` instruction sets ports to be publicly exposed when running the image.
  44. This is equivalent to do `docker commit -run '{"PortSpecs": ["<port>", "<port2>"]}'` outside the builder.
  45. 2.6 ENV
  46. -------
  47. ``ENV <key> <value>``
  48. The `ENV` instruction set as environment variable `<key>` with the value `<value>`. This value will be passed to all future ``RUN`` instructions.
  49. .. note::
  50. The environment variables are local to the Dockerfile, they will not be set as autorun.
  51. 2.7 INSERT
  52. ----------
  53. ``INSERT <file url> <path>``
  54. The `INSERT` instruction will download the file at the given url and place it within the image at the given path.
  55. .. note::
  56. The path must include the file name.
  57. 3. Dockerfile Examples
  58. ======================
  59. ::
  60. # Nginx
  61. #
  62. # VERSION 0.0.1
  63. # DOCKER-VERSION 0.2
  64. from ubuntu
  65. maintainer Guillaume J. Charmes "guillaume@dotcloud.com"
  66. # make sure the package repository is up to date
  67. run echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
  68. run apt-get update
  69. run apt-get install -y inotify-tools nginx apache2 openssh-server
  70. insert https://raw.github.com/creack/docker-vps/master/nginx-wrapper.sh /usr/sbin/nginx-wrapper
  71. ::
  72. # Firefox over VNC
  73. #
  74. # VERSION 0.3
  75. # DOCKER-VERSION 0.2
  76. from ubuntu
  77. # make sure the package repository is up to date
  78. run echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
  79. run apt-get update
  80. # Install vnc, xvfb in order to create a 'fake' display and firefox
  81. run apt-get install -y x11vnc xvfb firefox
  82. run mkdir /.vnc
  83. # Setup a password
  84. run x11vnc -storepasswd 1234 ~/.vnc/passwd
  85. # Autostart firefox (might not be the best way to do it, but it does the trick)
  86. run bash -c 'echo "firefox" >> /.bashrc'
  87. expose 5900
  88. cmd ["x11vnc", "-forever", "-usepw", "-create"]